home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / dwarfout.c < prev    next >
C/C++ Source or Header  |  1994-07-28  |  188KB  |  5,641 lines

  1. /* Output Dwarf format symbol table information from the GNU C compiler.
  2.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4.    Written by Ron Guilmette (rfg@netcom.com) for
  5.    Network Computing Devices, August, September, October, November 1990.
  6.    Generously contributed by NCD to the Free Software Foundation.
  7.  
  8. This file is part of GNU CC.
  9.  
  10. GNU CC is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14.  
  15. GNU CC is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with GNU CC; see the file COPYING.  If not, write to
  22. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  23.  
  24. #include "config.h"
  25.  
  26. #ifdef DWARF_DEBUGGING_INFO
  27. #include <stdio.h>
  28. #include "dwarf.h"
  29. #include "tree.h"
  30. #include "flags.h"
  31. #include "rtl.h"
  32. #include "hard-reg-set.h"
  33. #include "insn-config.h"
  34. #include "reload.h"
  35. #include "output.h"
  36. #include "defaults.h"
  37.  
  38. #ifndef DWARF_VERSION
  39. #define DWARF_VERSION 1
  40. #endif
  41.  
  42. /* #define NDEBUG 1 */
  43. #include "assert.h"
  44.  
  45. #if defined(DWARF_TIMESTAMPS)
  46. #if defined(POSIX)
  47. #include <time.h>
  48. #else /* !defined(POSIX) */
  49. #include <sys/types.h>
  50. #if defined(__STDC__)
  51. extern time_t time (time_t *);
  52. #else /* !defined(__STDC__) */
  53. extern time_t time ();
  54. #endif /* !defined(__STDC__) */
  55. #endif /* !defined(POSIX) */
  56. #endif /* defined(DWARF_TIMESTAMPS) */
  57.  
  58. extern char *getpwd ();
  59.  
  60. extern char *index ();
  61. extern char *rindex ();
  62.  
  63. /* IMPORTANT NOTE: Please see the file README.DWARF for important details
  64.    regarding the GNU implementation of Dwarf.  */
  65.  
  66. /* NOTE: In the comments in this file, many references are made to
  67.    so called "Debugging Information Entries".  For the sake of brevity,
  68.    this term is abbreviated to `DIE' throughout the remainder of this
  69.    file.  */
  70.  
  71. /* Note that the implementation of C++ support herein is (as yet) unfinished.
  72.    If you want to try to complete it, more power to you.  */
  73.  
  74. #if defined(__GNUC__) && (NDEBUG == 1)
  75. #define inline static inline
  76. #else
  77. #define inline static
  78. #endif
  79.  
  80. /* How to start an assembler comment.  */
  81. #ifndef ASM_COMMENT_START
  82. #define ASM_COMMENT_START ";#"
  83. #endif
  84.  
  85. /* How to print out a register name.  */
  86. #ifndef PRINT_REG
  87. #define PRINT_REG(RTX, CODE, FILE) \
  88.   fprintf ((FILE), "%s", reg_names[REGNO (RTX)])
  89. #endif
  90.  
  91. /* Define a macro which returns non-zero for any tagged type which is
  92.    used (directly or indirectly) in the specification of either some
  93.    function's return type or some formal parameter of some function.
  94.    We use this macro when we are operating in "terse" mode to help us
  95.    know what tagged types have to be represented in Dwarf (even in
  96.    terse mode) and which ones don't.
  97.  
  98.    A flag bit with this meaning really should be a part of the normal
  99.    GCC ..._TYPE nodes, but at the moment, there is no such bit defined
  100.    for these nodes.  For now, we have to just fake it.  It it safe for
  101.    us to simply return zero for all complete tagged types (which will
  102.    get forced out anyway if they were used in the specification of some
  103.    formal or return type) and non-zero for all incomplete tagged types.
  104. */
  105.  
  106. #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0)
  107.  
  108. extern int flag_traditional;
  109. extern char *version_string;
  110. extern char *language_string;
  111.  
  112. /* Maximum size (in bytes) of an artificially generated label.    */
  113.  
  114. #define MAX_ARTIFICIAL_LABEL_BYTES    30
  115.  
  116. /* Make sure we know the sizes of the various types dwarf can describe.
  117.    These are only defaults.  If the sizes are different for your target,
  118.    you should override these values by defining the appropriate symbols
  119.    in your tm.h file.  */
  120.  
  121. #ifndef CHAR_TYPE_SIZE
  122. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  123. #endif
  124.  
  125. #ifndef SHORT_TYPE_SIZE
  126. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
  127. #endif
  128.  
  129. #ifndef INT_TYPE_SIZE
  130. #define INT_TYPE_SIZE BITS_PER_WORD
  131. #endif
  132.  
  133. #ifndef LONG_TYPE_SIZE
  134. #define LONG_TYPE_SIZE BITS_PER_WORD
  135. #endif
  136.  
  137. #ifndef LONG_LONG_TYPE_SIZE
  138. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  139. #endif
  140.  
  141. #ifndef WCHAR_TYPE_SIZE
  142. #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
  143. #endif
  144.  
  145. #ifndef WCHAR_UNSIGNED
  146. #define WCHAR_UNSIGNED 0
  147. #endif
  148.  
  149. #ifndef FLOAT_TYPE_SIZE
  150. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  151. #endif
  152.  
  153. #ifndef DOUBLE_TYPE_SIZE
  154. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  155. #endif
  156.  
  157. #ifndef LONG_DOUBLE_TYPE_SIZE
  158. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  159. #endif
  160.  
  161. /* Structure to keep track of source filenames.  */
  162.  
  163. struct filename_entry {
  164.   unsigned    number;
  165.   char *    name;
  166. };
  167.  
  168. typedef struct filename_entry filename_entry;
  169.  
  170. /* Pointer to an array of elements, each one having the structure above. */
  171.  
  172. static filename_entry *filename_table;
  173.  
  174. /* Total number of entries in the table (i.e. array) pointed to by
  175.    `filename_table'.  This is the *total* and includes both used and
  176.    unused slots.  */
  177.  
  178. static unsigned ft_entries_allocated;
  179.  
  180. /* Number of entries in the filename_table which are actually in use.  */
  181.  
  182. static unsigned ft_entries;
  183.  
  184. /* Size (in elements) of increments by which we may expand the filename
  185.    table.  Actually, a single hunk of space of this size should be enough
  186.    for most typical programs.     */
  187.  
  188. #define FT_ENTRIES_INCREMENT 64
  189.  
  190. /* Local pointer to the name of the main input file.  Initialized in
  191.    dwarfout_init.  */
  192.  
  193. static char *primary_filename;
  194.  
  195. /* Pointer to the most recent filename for which we produced some line info.  */
  196.  
  197. static char *last_filename;
  198.  
  199. /* For Dwarf output, we must assign lexical-blocks id numbers
  200.    in the order in which their beginnings are encountered.
  201.    We output Dwarf debugging info that refers to the beginnings
  202.    and ends of the ranges of code for each lexical block with
  203.    assembler labels ..Bn and ..Bn.e, where n is the block number.
  204.    The labels themselves are generated in final.c, which assigns
  205.    numbers to the blocks in the same way.  */
  206.  
  207. static unsigned next_block_number = 2;
  208.  
  209. /* Counter to generate unique names for DIEs. */
  210.  
  211. static unsigned next_unused_dienum = 1;
  212.  
  213. /* Number of the DIE which is currently being generated.  */
  214.  
  215. static unsigned current_dienum;
  216.  
  217. /* Number to use for the special "pubname" label on the next DIE which
  218.    represents a function or data object defined in this compilation
  219.    unit which has "extern" linkage.  */
  220.  
  221. static next_pubname_number = 0;
  222.  
  223. #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1]
  224.  
  225. /* Pointer to a dynamically allocated list of pre-reserved and still
  226.    pending sibling DIE numbers.     Note that this list will grow as needed.  */
  227.  
  228. static unsigned *pending_sibling_stack;
  229.  
  230. /* Counter to keep track of the number of pre-reserved and still pending
  231.    sibling DIE numbers.     */
  232.  
  233. static unsigned pending_siblings;
  234.  
  235. /* The currently allocated size of the above list (expressed in number of
  236.    list elements).  */
  237.  
  238. static unsigned pending_siblings_allocated;
  239.  
  240. /* Size (in elements) of increments by which we may expand the pending
  241.    sibling stack.  Actually, a single hunk of space of this size should
  242.    be enough for most typical programs.     */
  243.  
  244. #define PENDING_SIBLINGS_INCREMENT 64
  245.  
  246. /* Non-zero if we are performing our file-scope finalization pass and if
  247.    we should force out Dwarf descriptions of any and all file-scope
  248.    tagged types which are still incomplete types.  */
  249.  
  250. static int finalizing = 0;
  251.  
  252. /* A pointer to the base of a list of pending types which we haven't
  253.    generated DIEs for yet, but which we will have to come back to
  254.    later on.  */
  255.  
  256. static tree *pending_types_list;
  257.  
  258. /* Number of elements currently allocated for the pending_types_list.  */
  259.  
  260. static unsigned pending_types_allocated;
  261.  
  262. /* Number of elements of pending_types_list currently in use.  */
  263.  
  264. static unsigned pending_types;
  265.  
  266. /* Size (in elements) of increments by which we may expand the pending
  267.    types list.  Actually, a single hunk of space of this size should
  268.    be enough for most typical programs.     */
  269.  
  270. #define PENDING_TYPES_INCREMENT 64
  271.  
  272. /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init.
  273.    This is used in a hack to help us get the DIEs describing types of
  274.    formal parameters to come *after* all of the DIEs describing the formal
  275.    parameters themselves.  That's necessary in order to be compatible
  276.    with what the brain-damaged svr4 SDB debugger requires.  */
  277.  
  278. static tree fake_containing_scope;
  279.  
  280. /* The number of the current function definition that we are generating
  281.    debugging information for.  These numbers range from 1 up to the maximum
  282.    number of function definitions contained within the current compilation
  283.    unit.  These numbers are used to create unique labels for various things
  284.    contained within various function definitions.  */
  285.  
  286. static unsigned current_funcdef_number = 1;
  287.  
  288. /* A pointer to the ..._DECL node which we have most recently been working
  289.    on.  We keep this around just in case something about it looks screwy
  290.    and we want to tell the user what the source coordinates for the actual
  291.    declaration are.  */
  292.  
  293. static tree dwarf_last_decl;
  294.  
  295. /* Forward declarations for functions defined in this file.  */
  296.  
  297. static void output_type ();
  298. static void type_attribute ();
  299. static void output_decls_for_scope ();
  300. static void output_decl ();
  301. static unsigned lookup_filename ();
  302.  
  303. /* Definitions of defaults for assembler-dependent names of various
  304.    pseudo-ops and section names.
  305.  
  306.    Theses may be overridden in your tm.h file (if necessary) for your
  307.    particular assembler.  The default values provided here correspond to
  308.    what is expected by "standard" AT&T System V.4 assemblers.  */
  309.  
  310. #ifndef FILE_ASM_OP
  311. #define FILE_ASM_OP        ".file"
  312. #endif
  313. #ifndef VERSION_ASM_OP
  314. #define VERSION_ASM_OP        ".version"
  315. #endif
  316. #ifndef UNALIGNED_SHORT_ASM_OP
  317. #define UNALIGNED_SHORT_ASM_OP    ".2byte"
  318. #endif
  319. #ifndef UNALIGNED_INT_ASM_OP
  320. #define UNALIGNED_INT_ASM_OP    ".4byte"
  321. #endif
  322. #ifndef ASM_BYTE_OP
  323. #define ASM_BYTE_OP        ".byte"
  324. #endif
  325. #ifndef SET_ASM_OP
  326. #define SET_ASM_OP        ".set"
  327. #endif
  328.  
  329. /* Pseudo-ops for pushing the current section onto the section stack (and
  330.    simultaneously changing to a new section) and for poping back to the
  331.    section we were in immediately before this one.  Note that most svr4
  332.    assemblers only maintain a one level stack... you can push all the
  333.    sections you want, but you can only pop out one level.  (The sparc
  334.    svr4 assembler is an exception to this general rule.)  That's
  335.    OK because we only use at most one level of the section stack herein.  */
  336.  
  337. #ifndef PUSHSECTION_ASM_OP
  338. #define PUSHSECTION_ASM_OP    ".section"
  339. #endif
  340. #ifndef POPSECTION_ASM_OP
  341. #define POPSECTION_ASM_OP    ".previous"
  342. #endif
  343.  
  344. /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below)
  345.    to print the PUSHSECTION_ASM_OP and the section name.  The default here
  346.    works for almost all svr4 assemblers, except for the sparc, where the
  347.    section name must be enclosed in double quotes.  (See sparcv4.h.)  */
  348.  
  349. #ifndef PUSHSECTION_FORMAT
  350. #define PUSHSECTION_FORMAT    "%s\t%s\n"
  351. #endif
  352.  
  353. #ifndef DEBUG_SECTION
  354. #define DEBUG_SECTION        ".debug"
  355. #endif
  356. #ifndef LINE_SECTION
  357. #define LINE_SECTION        ".line"
  358. #endif
  359. #ifndef SFNAMES_SECTION
  360. #define SFNAMES_SECTION        ".debug_sfnames"
  361. #endif
  362. #ifndef SRCINFO_SECTION
  363. #define SRCINFO_SECTION        ".debug_srcinfo"
  364. #endif
  365. #ifndef MACINFO_SECTION
  366. #define MACINFO_SECTION        ".debug_macinfo"
  367. #endif
  368. #ifndef PUBNAMES_SECTION
  369. #define PUBNAMES_SECTION    ".debug_pubnames"
  370. #endif
  371. #ifndef ARANGES_SECTION
  372. #define ARANGES_SECTION        ".debug_aranges"
  373. #endif
  374. #ifndef TEXT_SECTION
  375. #define TEXT_SECTION        ".text"
  376. #endif
  377. #ifndef DATA_SECTION
  378. #define DATA_SECTION        ".data"
  379. #endif
  380. #ifndef DATA1_SECTION
  381. #define DATA1_SECTION        ".data1"
  382. #endif
  383. #ifndef RODATA_SECTION
  384. #define RODATA_SECTION        ".rodata"
  385. #endif
  386. #ifndef RODATA1_SECTION
  387. #define RODATA1_SECTION        ".rodata1"
  388. #endif
  389. #ifndef BSS_SECTION
  390. #define BSS_SECTION        ".bss"
  391. #endif
  392.  
  393. /* Definitions of defaults for formats and names of various special
  394.    (artificial) labels which may be generated within this file (when
  395.    the -g options is used and DWARF_DEBUGGING_INFO is in effect.
  396.  
  397.    If necessary, these may be overridden from within your tm.h file,
  398.    but typically, you should never need to override these.
  399.  
  400.    These labels have been hacked (temporarily) so that they all begin with
  401.    a `.L' sequence so as to appease the stock sparc/svr4 assembler and the
  402.    stock m88k/svr4 assembler, both of which need to see .L at the start of
  403.    a label in order to prevent that label from going into the linker symbol
  404.    table).  When I get time, I'll have to fix this the right way so that we
  405.    will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein,
  406.    but that will require a rather massive set of changes.  For the moment,
  407.    the following definitions out to produce the right results for all svr4
  408.    and svr3 assemblers. -- rfg
  409. */
  410.  
  411. #ifndef TEXT_BEGIN_LABEL
  412. #define TEXT_BEGIN_LABEL    ".L_text_b"
  413. #endif
  414. #ifndef TEXT_END_LABEL
  415. #define TEXT_END_LABEL        ".L_text_e"
  416. #endif
  417.  
  418. #ifndef DATA_BEGIN_LABEL
  419. #define DATA_BEGIN_LABEL    ".L_data_b"
  420. #endif
  421. #ifndef DATA_END_LABEL
  422. #define DATA_END_LABEL        ".L_data_e"
  423. #endif
  424.  
  425. #ifndef DATA1_BEGIN_LABEL
  426. #define DATA1_BEGIN_LABEL    ".L_data1_b"
  427. #endif
  428. #ifndef DATA1_END_LABEL
  429. #define DATA1_END_LABEL        ".L_data1_e"
  430. #endif
  431.  
  432. #ifndef RODATA_BEGIN_LABEL
  433. #define RODATA_BEGIN_LABEL    ".L_rodata_b"
  434. #endif
  435. #ifndef RODATA_END_LABEL
  436. #define RODATA_END_LABEL    ".L_rodata_e"
  437. #endif
  438.  
  439. #ifndef RODATA1_BEGIN_LABEL
  440. #define RODATA1_BEGIN_LABEL    ".L_rodata1_b"
  441. #endif
  442. #ifndef RODATA1_END_LABEL
  443. #define RODATA1_END_LABEL    ".L_rodata1_e"
  444. #endif
  445.  
  446. #ifndef BSS_BEGIN_LABEL
  447. #define BSS_BEGIN_LABEL        ".L_bss_b"
  448. #endif
  449. #ifndef BSS_END_LABEL
  450. #define BSS_END_LABEL        ".L_bss_e"
  451. #endif
  452.  
  453. #ifndef LINE_BEGIN_LABEL
  454. #define LINE_BEGIN_LABEL    ".L_line_b"
  455. #endif
  456. #ifndef LINE_LAST_ENTRY_LABEL
  457. #define LINE_LAST_ENTRY_LABEL    ".L_line_last"
  458. #endif
  459. #ifndef LINE_END_LABEL
  460. #define LINE_END_LABEL        ".L_line_e"
  461. #endif
  462.  
  463. #ifndef DEBUG_BEGIN_LABEL
  464. #define DEBUG_BEGIN_LABEL    ".L_debug_b"
  465. #endif
  466. #ifndef SFNAMES_BEGIN_LABEL
  467. #define SFNAMES_BEGIN_LABEL    ".L_sfnames_b"
  468. #endif
  469. #ifndef SRCINFO_BEGIN_LABEL
  470. #define SRCINFO_BEGIN_LABEL    ".L_srcinfo_b"
  471. #endif
  472. #ifndef MACINFO_BEGIN_LABEL
  473. #define MACINFO_BEGIN_LABEL    ".L_macinfo_b"
  474. #endif
  475.  
  476. #ifndef DIE_BEGIN_LABEL_FMT
  477. #define DIE_BEGIN_LABEL_FMT    ".L_D%u"
  478. #endif
  479. #ifndef DIE_END_LABEL_FMT
  480. #define DIE_END_LABEL_FMT    ".L_D%u_e"
  481. #endif
  482. #ifndef PUB_DIE_LABEL_FMT
  483. #define PUB_DIE_LABEL_FMT    ".L_P%u"
  484. #endif
  485. #ifndef INSN_LABEL_FMT
  486. #define INSN_LABEL_FMT        ".L_I%u_%u"
  487. #endif
  488. #ifndef BLOCK_BEGIN_LABEL_FMT
  489. #define BLOCK_BEGIN_LABEL_FMT    ".L_B%u"
  490. #endif
  491. #ifndef BLOCK_END_LABEL_FMT
  492. #define BLOCK_END_LABEL_FMT    ".L_B%u_e"
  493. #endif
  494. #ifndef SS_BEGIN_LABEL_FMT
  495. #define SS_BEGIN_LABEL_FMT    ".L_s%u"
  496. #endif
  497. #ifndef SS_END_LABEL_FMT
  498. #define SS_END_LABEL_FMT    ".L_s%u_e"
  499. #endif
  500. #ifndef EE_BEGIN_LABEL_FMT
  501. #define EE_BEGIN_LABEL_FMT    ".L_e%u"
  502. #endif
  503. #ifndef EE_END_LABEL_FMT
  504. #define EE_END_LABEL_FMT    ".L_e%u_e"
  505. #endif
  506. #ifndef MT_BEGIN_LABEL_FMT
  507. #define MT_BEGIN_LABEL_FMT    ".L_t%u"
  508. #endif
  509. #ifndef MT_END_LABEL_FMT
  510. #define MT_END_LABEL_FMT    ".L_t%u_e"
  511. #endif
  512. #ifndef LOC_BEGIN_LABEL_FMT
  513. #define LOC_BEGIN_LABEL_FMT    ".L_l%u"
  514. #endif
  515. #ifndef LOC_END_LABEL_FMT
  516. #define LOC_END_LABEL_FMT    ".L_l%u_e"
  517. #endif
  518. #ifndef BOUND_BEGIN_LABEL_FMT
  519. #define BOUND_BEGIN_LABEL_FMT    ".L_b%u_%u_%c"
  520. #endif
  521. #ifndef BOUND_END_LABEL_FMT
  522. #define BOUND_END_LABEL_FMT    ".L_b%u_%u_%c_e"
  523. #endif
  524. #ifndef DERIV_BEGIN_LABEL_FMT
  525. #define DERIV_BEGIN_LABEL_FMT    ".L_d%u"
  526. #endif
  527. #ifndef DERIV_END_LABEL_FMT
  528. #define DERIV_END_LABEL_FMT    ".L_d%u_e"
  529. #endif
  530. #ifndef SL_BEGIN_LABEL_FMT
  531. #define SL_BEGIN_LABEL_FMT    ".L_sl%u"
  532. #endif
  533. #ifndef SL_END_LABEL_FMT
  534. #define SL_END_LABEL_FMT    ".L_sl%u_e"
  535. #endif
  536. #ifndef BODY_BEGIN_LABEL_FMT
  537. #define BODY_BEGIN_LABEL_FMT    ".L_b%u"
  538. #endif
  539. #ifndef BODY_END_LABEL_FMT
  540. #define BODY_END_LABEL_FMT    ".L_b%u_e"
  541. #endif
  542. #ifndef FUNC_END_LABEL_FMT
  543. #define FUNC_END_LABEL_FMT    ".L_f%u_e"
  544. #endif
  545. #ifndef TYPE_NAME_FMT
  546. #define TYPE_NAME_FMT        ".L_T%u"
  547. #endif
  548. #ifndef DECL_NAME_FMT
  549. #define DECL_NAME_FMT        ".L_E%u"
  550. #endif
  551. #ifndef LINE_CODE_LABEL_FMT
  552. #define LINE_CODE_LABEL_FMT    ".L_LC%u"
  553. #endif
  554. #ifndef SFNAMES_ENTRY_LABEL_FMT
  555. #define SFNAMES_ENTRY_LABEL_FMT    ".L_F%u"
  556. #endif
  557. #ifndef LINE_ENTRY_LABEL_FMT
  558. #define LINE_ENTRY_LABEL_FMT    ".L_LE%u"
  559. #endif
  560.  
  561. /* Definitions of defaults for various types of primitive assembly language
  562.    output operations.
  563.  
  564.    If necessary, these may be overridden from within your tm.h file,
  565.    but typically, you shouldn't need to override these.  */
  566.  
  567. #ifndef ASM_OUTPUT_PUSH_SECTION
  568. #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \
  569.   fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION)
  570. #endif
  571.  
  572. #ifndef ASM_OUTPUT_POP_SECTION
  573. #define ASM_OUTPUT_POP_SECTION(FILE) \
  574.   fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP)
  575. #endif
  576.  
  577. #ifndef ASM_OUTPUT_SOURCE_FILENAME
  578. #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
  579.   do {    fprintf (FILE, "\t%s\t", FILE_ASM_OP);                \
  580.     output_quoted_string (FILE, NAME);                \
  581.     fputc ('\n', FILE);                        \
  582.   } while (0)
  583. #endif
  584.  
  585. #ifndef ASM_OUTPUT_DWARF_DELTA2
  586. #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)            \
  587.  do {    fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);        \
  588.     assemble_name (FILE, LABEL1);                    \
  589.     fprintf (FILE, "-");                        \
  590.     assemble_name (FILE, LABEL2);                    \
  591.     fprintf (FILE, "\n");                        \
  592.   } while (0)
  593. #endif
  594.  
  595. #ifndef ASM_OUTPUT_DWARF_DELTA4
  596. #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)            \
  597.  do {    fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);        \
  598.     assemble_name (FILE, LABEL1);                    \
  599.     fprintf (FILE, "-");                        \
  600.     assemble_name (FILE, LABEL2);                    \
  601.     fprintf (FILE, "\n");                        \
  602.   } while (0)
  603. #endif
  604.  
  605. #ifndef ASM_OUTPUT_DWARF_TAG
  606. #define ASM_OUTPUT_DWARF_TAG(FILE,TAG)                    \
  607.   do {                                    \
  608.     fprintf ((FILE), "\t%s\t0x%x",                    \
  609.              UNALIGNED_SHORT_ASM_OP, (unsigned) TAG);        \
  610.     if (flag_verbose_asm)                        \
  611.       fprintf ((FILE), "\t%s %s",                    \
  612.                ASM_COMMENT_START, dwarf_tag_name (TAG));    \
  613.     fputc ('\n', (FILE));                        \
  614.   } while (0)
  615. #endif
  616.  
  617. #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
  618. #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR)                \
  619.   do {                                    \
  620.     fprintf ((FILE), "\t%s\t0x%x",                    \
  621.              UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR);        \
  622.     if (flag_verbose_asm)                        \
  623.       fprintf ((FILE), "\t%s %s",                    \
  624.                ASM_COMMENT_START, dwarf_attr_name (ATTR));    \
  625.     fputc ('\n', (FILE));                        \
  626.   } while (0)
  627. #endif
  628.  
  629. #ifndef ASM_OUTPUT_DWARF_STACK_OP
  630. #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP)                \
  631.   do {                                    \
  632.     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP);        \
  633.     if (flag_verbose_asm)                        \
  634.       fprintf ((FILE), "\t%s %s",                    \
  635.                ASM_COMMENT_START, dwarf_stack_op_name (OP));    \
  636.     fputc ('\n', (FILE));                        \
  637.   } while (0)
  638. #endif
  639.  
  640. #ifndef ASM_OUTPUT_DWARF_FUND_TYPE
  641. #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT)                \
  642.   do {                                    \
  643.     fprintf ((FILE), "\t%s\t0x%x",                    \
  644.              UNALIGNED_SHORT_ASM_OP, (unsigned) FT);        \
  645.     if (flag_verbose_asm)                        \
  646.       fprintf ((FILE), "\t%s %s",                    \
  647.                ASM_COMMENT_START, dwarf_fund_type_name (FT));    \
  648.     fputc ('\n', (FILE));                        \
  649.   } while (0)
  650. #endif
  651.  
  652. #ifndef ASM_OUTPUT_DWARF_FMT_BYTE
  653. #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT)                \
  654.   do {                                    \
  655.     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT);    \
  656.     if (flag_verbose_asm)                        \
  657.       fprintf ((FILE), "\t%s %s",                    \
  658.                ASM_COMMENT_START, dwarf_fmt_byte_name (FMT));    \
  659.     fputc ('\n', (FILE));                        \
  660.   } while (0)
  661. #endif
  662.  
  663. #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER
  664. #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD)            \
  665.   do {                                    \
  666.     fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD);    \
  667.     if (flag_verbose_asm)                        \
  668.       fprintf ((FILE), "\t%s %s",                    \
  669.                ASM_COMMENT_START, dwarf_typemod_name (MOD));    \
  670.     fputc ('\n', (FILE));                        \
  671.   } while (0)
  672. #endif
  673.  
  674. #ifndef ASM_OUTPUT_DWARF_ADDR
  675. #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                \
  676.  do {    fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);        \
  677.     assemble_name (FILE, LABEL);                    \
  678.     fprintf (FILE, "\n");                        \
  679.   } while (0)
  680. #endif
  681.  
  682. #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
  683. #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX)                \
  684.   do {                                    \
  685.     fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);            \
  686.     output_addr_const ((FILE), (RTX));                    \
  687.     fputc ('\n', (FILE));                        \
  688.   } while (0)
  689. #endif
  690.  
  691. #ifndef ASM_OUTPUT_DWARF_REF
  692. #define ASM_OUTPUT_DWARF_REF(FILE,LABEL)                \
  693.  do {    fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);        \
  694.     assemble_name (FILE, LABEL);                    \
  695.     fprintf (FILE, "\n");                        \
  696.   } while (0)
  697. #endif
  698.  
  699. #ifndef ASM_OUTPUT_DWARF_DATA1
  700. #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
  701.   fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE)
  702. #endif
  703.  
  704. #ifndef ASM_OUTPUT_DWARF_DATA2
  705. #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
  706.   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
  707. #endif
  708.  
  709. #ifndef ASM_OUTPUT_DWARF_DATA4
  710. #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
  711.   fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
  712. #endif
  713.  
  714. #ifndef ASM_OUTPUT_DWARF_DATA8
  715. #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)        \
  716.   do {                                    \
  717.     if (WORDS_BIG_ENDIAN)                        \
  718.       {                                    \
  719.     fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
  720.     fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
  721.       }                                    \
  722.     else                                \
  723.       {                                    \
  724.     fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
  725.     fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
  726.       }                                    \
  727.   } while (0)
  728. #endif
  729.  
  730. #ifndef ASM_OUTPUT_DWARF_STRING
  731. #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
  732.   ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
  733. #endif
  734.  
  735. /************************ general utility functions **************************/
  736.  
  737. inline char *
  738. xstrdup (s)
  739.      register char *s;
  740. {
  741.   register char *p = (char *) xmalloc (strlen (s) + 1);
  742.  
  743.   strcpy (p, s);
  744.   return p;
  745. }
  746.  
  747. inline int
  748. is_pseudo_reg (rtl)
  749.      register rtx rtl;
  750. {
  751.   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
  752.           || ((GET_CODE (rtl) == SUBREG)
  753.           && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
  754. }
  755.  
  756. inline tree
  757. type_main_variant (type)
  758.      register tree type;
  759. {
  760.   type = TYPE_MAIN_VARIANT (type);
  761.  
  762.   /* There really should be only one main variant among any group of variants
  763.      of a given type (and all of the MAIN_VARIANT values for all members of
  764.      the group should point to that one type) but sometimes the C front-end
  765.      messes this up for array types, so we work around that bug here.  */
  766.  
  767.   if (TREE_CODE (type) == ARRAY_TYPE)
  768.     {
  769.       while (type != TYPE_MAIN_VARIANT (type))
  770.         type = TYPE_MAIN_VARIANT (type);
  771.     }
  772.  
  773.   return type;
  774. }
  775.  
  776. /* Return non-zero if the given type node represents a tagged type.  */
  777.  
  778. inline int
  779. is_tagged_type (type)
  780.      register tree type;
  781. {
  782.   register enum tree_code code = TREE_CODE (type);
  783.  
  784.   return (code == RECORD_TYPE || code == UNION_TYPE
  785.       || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
  786. }
  787.  
  788. static char *
  789. dwarf_tag_name (tag)
  790.      register unsigned tag;
  791. {
  792.   switch (tag)
  793.     {
  794.     case TAG_padding:            return "TAG_padding";
  795.     case TAG_array_type:        return "TAG_array_type";
  796.     case TAG_class_type:        return "TAG_class_type";
  797.     case TAG_entry_point:        return "TAG_entry_point";
  798.     case TAG_enumeration_type:        return "TAG_enumeration_type";
  799.     case TAG_formal_parameter:        return "TAG_formal_parameter";
  800.     case TAG_global_subroutine:        return "TAG_global_subroutine";
  801.     case TAG_global_variable:        return "TAG_global_variable";
  802.     case TAG_label:            return "TAG_label";
  803.     case TAG_lexical_block:        return "TAG_lexical_block";
  804.     case TAG_local_variable:        return "TAG_local_variable";
  805.     case TAG_member:            return "TAG_member";
  806.     case TAG_pointer_type:        return "TAG_pointer_type";
  807.     case TAG_reference_type:        return "TAG_reference_type";
  808.     case TAG_compile_unit:        return "TAG_compile_unit";
  809.     case TAG_string_type:        return "TAG_string_type";
  810.     case TAG_structure_type:        return "TAG_structure_type";
  811.     case TAG_subroutine:        return "TAG_subroutine";
  812.     case TAG_subroutine_type:        return "TAG_subroutine_type";
  813.     case TAG_typedef:            return "TAG_typedef";
  814.     case TAG_union_type:        return "TAG_union_type";
  815.     case TAG_unspecified_parameters:    return "TAG_unspecified_parameters";
  816.     case TAG_variant:            return "TAG_variant";
  817.     case TAG_common_block:        return "TAG_common_block";
  818.     case TAG_common_inclusion:        return "TAG_common_inclusion";
  819.     case TAG_inheritance:        return "TAG_inheritance";
  820.     case TAG_inlined_subroutine:    return "TAG_inlined_subroutine";
  821.     case TAG_module:            return "TAG_module";
  822.     case TAG_ptr_to_member_type:    return "TAG_ptr_to_member_type";
  823.     case TAG_set_type:            return "TAG_set_type";
  824.     case TAG_subrange_type:        return "TAG_subrange_type";
  825.     case TAG_with_stmt:            return "TAG_with_stmt";
  826.  
  827.     /* GNU extensions.  */
  828.  
  829.     case TAG_format_label:        return "TAG_format_label";
  830.     case TAG_namelist:            return "TAG_namelist";
  831.     case TAG_function_template:        return "TAG_function_template";
  832.     case TAG_class_template:        return "TAG_class_template";
  833.  
  834.     default:                return "TAG_<unknown>";
  835.     }
  836. }
  837.  
  838. static char *
  839. dwarf_attr_name (attr)
  840.      register unsigned attr;
  841. {
  842.   switch (attr)
  843.     {
  844.     case AT_sibling:            return "AT_sibling";
  845.     case AT_location:            return "AT_location";
  846.     case AT_name:            return "AT_name";
  847.     case AT_fund_type:            return "AT_fund_type";
  848.     case AT_mod_fund_type:        return "AT_mod_fund_type";
  849.     case AT_user_def_type:        return "AT_user_def_type";
  850.     case AT_mod_u_d_type:        return "AT_mod_u_d_type";
  851.     case AT_ordering:            return "AT_ordering";
  852.     case AT_subscr_data:        return "AT_subscr_data";
  853.     case AT_byte_size:            return "AT_byte_size";
  854.     case AT_bit_offset:            return "AT_bit_offset";
  855.     case AT_bit_size:            return "AT_bit_size";
  856.     case AT_element_list:        return "AT_element_list";
  857.     case AT_stmt_list:            return "AT_stmt_list";
  858.     case AT_low_pc:            return "AT_low_pc";
  859.     case AT_high_pc:            return "AT_high_pc";
  860.     case AT_language:            return "AT_language";
  861.     case AT_member:            return "AT_member";
  862.     case AT_discr:            return "AT_discr";
  863.     case AT_discr_value:        return "AT_discr_value";
  864.     case AT_string_length:        return "AT_string_length";
  865.     case AT_common_reference:        return "AT_common_reference";
  866.     case AT_comp_dir:            return "AT_comp_dir";
  867.     case AT_const_value_string:        return "AT_const_value_string";
  868.     case AT_const_value_data2:        return "AT_const_value_data2";
  869.     case AT_const_value_data4:        return "AT_const_value_data4";
  870.     case AT_const_value_data8:        return "AT_const_value_data8";
  871.     case AT_const_value_block2:        return "AT_const_value_block2";
  872.     case AT_const_value_block4:        return "AT_const_value_block4";
  873.     case AT_containing_type:        return "AT_containing_type";
  874.     case AT_default_value_addr:        return "AT_default_value_addr";
  875.     case AT_default_value_data2:    return "AT_default_value_data2";
  876.     case AT_default_value_data4:    return "AT_default_value_data4";
  877.     case AT_default_value_data8:    return "AT_default_value_data8";
  878.     case AT_default_value_string:    return "AT_default_value_string";
  879.     case AT_friends:            return "AT_friends";
  880.     case AT_inline:            return "AT_inline";
  881.     case AT_is_optional:        return "AT_is_optional";
  882.     case AT_lower_bound_ref:        return "AT_lower_bound_ref";
  883.     case AT_lower_bound_data2:        return "AT_lower_bound_data2";
  884.     case AT_lower_bound_data4:        return "AT_lower_bound_data4";
  885.     case AT_lower_bound_data8:        return "AT_lower_bound_data8";
  886.     case AT_private:            return "AT_private";
  887.     case AT_producer:            return "AT_producer";
  888.     case AT_program:            return "AT_program";
  889.     case AT_protected:            return "AT_protected";
  890.     case AT_prototyped:            return "AT_prototyped";
  891.     case AT_public:            return "AT_public";
  892.     case AT_pure_virtual:        return "AT_pure_virtual";
  893.     case AT_return_addr:        return "AT_return_addr";
  894.     case AT_abstract_origin:        return "AT_abstract_origin";
  895.     case AT_start_scope:        return "AT_start_scope";
  896.     case AT_stride_size:        return "AT_stride_size";
  897.     case AT_upper_bound_ref:        return "AT_upper_bound_ref";
  898.     case AT_upper_bound_data2:        return "AT_upper_bound_data2";
  899.     case AT_upper_bound_data4:        return "AT_upper_bound_data4";
  900.     case AT_upper_bound_data8:        return "AT_upper_bound_data8";
  901.     case AT_virtual:            return "AT_virtual";
  902.  
  903.     /* GNU extensions */
  904.  
  905.     case AT_sf_names:            return "AT_sf_names";
  906.     case AT_src_info:            return "AT_src_info";
  907.     case AT_mac_info:            return "AT_mac_info";
  908.     case AT_src_coords:            return "AT_src_coords";
  909.     case AT_body_begin:            return "AT_body_begin";
  910.     case AT_body_end:            return "AT_body_end";
  911.  
  912.     default:                return "AT_<unknown>";
  913.     }
  914. }
  915.  
  916. static char *
  917. dwarf_stack_op_name (op)
  918.      register unsigned op;
  919. {
  920.   switch (op)
  921.     {
  922.     case OP_REG:        return "OP_REG";
  923.     case OP_BASEREG:        return "OP_BASEREG";
  924.     case OP_ADDR:        return "OP_ADDR";
  925.     case OP_CONST:        return "OP_CONST";
  926.     case OP_DEREF2:        return "OP_DEREF2";
  927.     case OP_DEREF4:        return "OP_DEREF4";
  928.     case OP_ADD:        return "OP_ADD";
  929.     default:            return "OP_<unknown>";
  930.     }
  931. }
  932.  
  933. static char *
  934. dwarf_typemod_name (mod)
  935.      register unsigned mod;
  936. {
  937.   switch (mod)
  938.     {
  939.     case MOD_pointer_to:    return "MOD_pointer_to";
  940.     case MOD_reference_to:    return "MOD_reference_to";
  941.     case MOD_const:        return "MOD_const";
  942.     case MOD_volatile:        return "MOD_volatile";
  943.     default:            return "MOD_<unknown>";
  944.     }
  945. }
  946.  
  947. static char *
  948. dwarf_fmt_byte_name (fmt)
  949.      register unsigned fmt;
  950. {
  951.   switch (fmt)
  952.     {
  953.     case FMT_FT_C_C:    return "FMT_FT_C_C";
  954.     case FMT_FT_C_X:    return "FMT_FT_C_X";
  955.     case FMT_FT_X_C:    return "FMT_FT_X_C";
  956.     case FMT_FT_X_X:    return "FMT_FT_X_X";
  957.     case FMT_UT_C_C:    return "FMT_UT_C_C";
  958.     case FMT_UT_C_X:    return "FMT_UT_C_X";
  959.     case FMT_UT_X_C:    return "FMT_UT_X_C";
  960.     case FMT_UT_X_X:    return "FMT_UT_X_X";
  961.     case FMT_ET:    return "FMT_ET";
  962.     default:        return "FMT_<unknown>";
  963.     }
  964. }
  965. static char *
  966. dwarf_fund_type_name (ft)
  967.      register unsigned ft;
  968. {
  969.   switch (ft)
  970.     {
  971.     case FT_char:        return "FT_char";
  972.     case FT_signed_char:    return "FT_signed_char";
  973.     case FT_unsigned_char:    return "FT_unsigned_char";
  974.     case FT_short:        return "FT_short";
  975.     case FT_signed_short:    return "FT_signed_short";
  976.     case FT_unsigned_short:    return "FT_unsigned_short";
  977.     case FT_integer:        return "FT_integer";
  978.     case FT_signed_integer:    return "FT_signed_integer";
  979.     case FT_unsigned_integer:    return "FT_unsigned_integer";
  980.     case FT_long:        return "FT_long";
  981.     case FT_signed_long:    return "FT_signed_long";
  982.     case FT_unsigned_long:    return "FT_unsigned_long";
  983.     case FT_pointer:        return "FT_pointer";
  984.     case FT_float:        return "FT_float";
  985.     case FT_dbl_prec_float:    return "FT_dbl_prec_float";
  986.     case FT_ext_prec_float:    return "FT_ext_prec_float";
  987.     case FT_complex:        return "FT_complex";
  988.     case FT_dbl_prec_complex:    return "FT_dbl_prec_complex";
  989.     case FT_void:        return "FT_void";
  990.     case FT_boolean:        return "FT_boolean";
  991.     case FT_ext_prec_complex:    return "FT_ext_prec_complex";
  992.     case FT_label:        return "FT_label";
  993.  
  994.     /* GNU extensions.  */
  995.  
  996.     case FT_long_long:        return "FT_long_long";
  997.     case FT_signed_long_long:    return "FT_signed_long_long";
  998.     case FT_unsigned_long_long: return "FT_unsigned_long_long";
  999.  
  1000.     case FT_int8:        return "FT_int8";
  1001.     case FT_signed_int8:    return "FT_signed_int8";
  1002.     case FT_unsigned_int8:    return "FT_unsigned_int8";
  1003.     case FT_int16:        return "FT_int16";
  1004.     case FT_signed_int16:    return "FT_signed_int16";
  1005.     case FT_unsigned_int16:    return "FT_unsigned_int16";
  1006.     case FT_int32:        return "FT_int32";
  1007.     case FT_signed_int32:    return "FT_signed_int32";
  1008.     case FT_unsigned_int32:    return "FT_unsigned_int32";
  1009.     case FT_int64:        return "FT_int64";
  1010.     case FT_signed_int64:    return "FT_signed_int64";
  1011.     case FT_unsigned_int64:    return "FT_signed_int64";
  1012.  
  1013.     case FT_real32:        return "FT_real32";
  1014.     case FT_real64:        return "FT_real64";
  1015.     case FT_real96:        return "FT_real96";
  1016.     case FT_real128:        return "FT_real128";
  1017.  
  1018.     default:            return "FT_<unknown>";
  1019.     }
  1020. }
  1021.  
  1022. /* Determine the "ultimate origin" of a decl.  The decl may be an
  1023.    inlined instance of an inlined instance of a decl which is local
  1024.    to an inline function, so we have to trace all of the way back
  1025.    through the origin chain to find out what sort of node actually
  1026.    served as the original seed for the given block.  */
  1027.  
  1028. static tree
  1029. decl_ultimate_origin (decl)
  1030.      register tree decl;
  1031. {
  1032.   register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
  1033.  
  1034.   if (immediate_origin == NULL)
  1035.     return NULL;
  1036.   else
  1037.     {
  1038.       register tree ret_val;
  1039.       register tree lookahead = immediate_origin;
  1040.  
  1041.       do
  1042.     {
  1043.       ret_val = lookahead;
  1044.       lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
  1045.     }
  1046.       while (lookahead != NULL && lookahead != ret_val);
  1047.       return ret_val;
  1048.     }
  1049. }
  1050.  
  1051. /* Determine the "ultimate origin" of a block.  The block may be an
  1052.    inlined instance of an inlined instance of a block which is local
  1053.    to an inline function, so we have to trace all of the way back
  1054.    through the origin chain to find out what sort of node actually
  1055.    served as the original seed for the given block.  */
  1056.  
  1057. static tree
  1058. block_ultimate_origin (block)
  1059.      register tree block;
  1060. {
  1061.   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
  1062.  
  1063.   if (immediate_origin == NULL)
  1064.     return NULL;
  1065.   else
  1066.     {
  1067.       register tree ret_val;
  1068.       register tree lookahead = immediate_origin;
  1069.  
  1070.       do
  1071.     {
  1072.       ret_val = lookahead;
  1073.       lookahead = (TREE_CODE (ret_val) == BLOCK)
  1074.                ? BLOCK_ABSTRACT_ORIGIN (ret_val)
  1075.                : NULL;
  1076.     }
  1077.       while (lookahead != NULL && lookahead != ret_val);
  1078.       return ret_val;
  1079.     }
  1080. }
  1081.  
  1082. static void
  1083. output_unsigned_leb128 (value)
  1084.      register unsigned long value;
  1085. {
  1086.   register unsigned long orig_value = value;
  1087.  
  1088.   do
  1089.     {
  1090.       register unsigned byte = (value & 0x7f);
  1091.  
  1092.       value >>= 7;
  1093.       if (value != 0)    /* more bytes to follow */
  1094.     byte |= 0x80;
  1095.       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
  1096.       if (flag_verbose_asm && value == 0)
  1097.     fprintf (asm_out_file, "\t%s ULEB128 number - value = %u",
  1098.          ASM_COMMENT_START, orig_value);
  1099.       fputc ('\n', asm_out_file);
  1100.     }
  1101.   while (value != 0);
  1102. }
  1103.  
  1104. static void
  1105. output_signed_leb128 (value)
  1106.      register long value;
  1107. {
  1108.   register long orig_value = value;
  1109.   register int negative = (value < 0);
  1110.   register int more;
  1111.  
  1112.   do
  1113.     {
  1114.       register unsigned byte = (value & 0x7f);
  1115.  
  1116.       value >>= 7;
  1117.       if (negative)
  1118.     value |= 0xfe000000;  /* manually sign extend */
  1119.       if (((value == 0) && ((byte & 0x40) == 0))
  1120.           || ((value == -1) && ((byte & 0x40) == 1)))
  1121.     more = 0;
  1122.       else
  1123.     {
  1124.       byte |= 0x80;
  1125.       more = 1;
  1126.     }
  1127.       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte);
  1128.       if (flag_verbose_asm && more == 0)
  1129.     fprintf (asm_out_file, "\t%s SLEB128 number - value = %d",
  1130.          ASM_COMMENT_START, orig_value);
  1131.       fputc ('\n', asm_out_file);
  1132.     }
  1133.   while (more);
  1134. }
  1135.  
  1136. /**************** utility functions for attribute functions ******************/
  1137.  
  1138. /* Given a pointer to a BLOCK node return non-zero if (and only if) the
  1139.    node in question represents the outermost pair of curly braces (i.e.
  1140.    the "body block") of a function or method.
  1141.  
  1142.    For any BLOCK node representing a "body block" of a function or method,
  1143.    the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node
  1144.    which represents the outermost (function) scope for the function or
  1145.    method (i.e. the one which includes the formal parameters).  The
  1146.    BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant
  1147.    FUNCTION_DECL node.
  1148. */
  1149.  
  1150. inline int
  1151. is_body_block (stmt)
  1152.      register tree stmt;
  1153. {
  1154.   if (TREE_CODE (stmt) == BLOCK)
  1155.     {
  1156.       register tree parent = BLOCK_SUPERCONTEXT (stmt);
  1157.  
  1158.       if (TREE_CODE (parent) == BLOCK)
  1159.     {
  1160.       register tree grandparent = BLOCK_SUPERCONTEXT (parent);
  1161.  
  1162.       if (TREE_CODE (grandparent) == FUNCTION_DECL)
  1163.         return 1;
  1164.     }
  1165.     }
  1166.   return 0;
  1167. }
  1168.  
  1169. /* Given a pointer to a tree node for some type, return a Dwarf fundamental
  1170.    type code for the given type.
  1171.  
  1172.    This routine must only be called for GCC type nodes that correspond to
  1173.    Dwarf fundamental types.
  1174.  
  1175.    The current Dwarf draft specification calls for Dwarf fundamental types
  1176.    to accurately reflect the fact that a given type was either a "plain"
  1177.    integral type or an explicitly "signed" integral type.  Unfortunately,
  1178.    we can't always do this, because GCC may already have thrown away the
  1179.    information about the precise way in which the type was originally
  1180.    specified, as in:
  1181.  
  1182.     typedef signed int my_type;
  1183.  
  1184.     struct s { my_type f; };
  1185.  
  1186.    Since we may be stuck here without enought information to do exactly
  1187.    what is called for in the Dwarf draft specification, we do the best
  1188.    that we can under the circumstances and always use the "plain" integral
  1189.    fundamental type codes for int, short, and long types.  That's probably
  1190.    good enough.  The additional accuracy called for in the current DWARF
  1191.    draft specification is probably never even useful in practice.  */
  1192.  
  1193. static int
  1194. fundamental_type_code (type)
  1195.      register tree type;
  1196. {
  1197.   if (TREE_CODE (type) == ERROR_MARK)
  1198.     return 0;
  1199.  
  1200.   switch (TREE_CODE (type))
  1201.     {
  1202.       case ERROR_MARK:
  1203.     return FT_void;
  1204.  
  1205.       case VOID_TYPE:
  1206.     return FT_void;
  1207.  
  1208.       case INTEGER_TYPE:
  1209.     /* Carefully distinguish all the standard types of C,
  1210.        without messing up if the language is not C.
  1211.        Note that we check only for the names that contain spaces;
  1212.        other names might occur by coincidence in other languages.  */
  1213.     if (TYPE_NAME (type) != 0
  1214.         && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1215.         && DECL_NAME (TYPE_NAME (type)) != 0
  1216.         && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
  1217.       {
  1218.         char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  1219.  
  1220.         if (!strcmp (name, "unsigned char"))
  1221.           return FT_unsigned_char;
  1222.         if (!strcmp (name, "signed char"))
  1223.           return FT_signed_char;
  1224.         if (!strcmp (name, "unsigned int"))
  1225.           return FT_unsigned_integer;
  1226.         if (!strcmp (name, "short int"))
  1227.           return FT_short;
  1228.         if (!strcmp (name, "short unsigned int"))
  1229.           return FT_unsigned_short;
  1230.         if (!strcmp (name, "long int"))
  1231.           return FT_long;
  1232.         if (!strcmp (name, "long unsigned int"))
  1233.           return FT_unsigned_long;
  1234.         if (!strcmp (name, "long long int"))
  1235.           return FT_long_long;        /* Not grok'ed by svr4 SDB */
  1236.         if (!strcmp (name, "long long unsigned int"))
  1237.           return FT_unsigned_long_long;    /* Not grok'ed by svr4 SDB */
  1238.       }
  1239.  
  1240.     /* Most integer types will be sorted out above, however, for the
  1241.        sake of special `array index' integer types, the following code
  1242.        is also provided.  */
  1243.  
  1244.     if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
  1245.       return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
  1246.  
  1247.     if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
  1248.       return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
  1249.  
  1250.     if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
  1251.       return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
  1252.  
  1253.     if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
  1254.       return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
  1255.  
  1256.     if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
  1257.       return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
  1258.  
  1259.     abort ();
  1260.  
  1261.       case REAL_TYPE:
  1262.     /* Carefully distinguish all the standard types of C,
  1263.        without messing up if the language is not C.  */
  1264.     if (TYPE_NAME (type) != 0
  1265.         && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  1266.         && DECL_NAME (TYPE_NAME (type)) != 0
  1267.         && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
  1268.       {
  1269.         char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  1270.  
  1271.         /* Note that here we can run afowl of a serious bug in "classic"
  1272.            svr4 SDB debuggers.  They don't seem to understand the
  1273.            FT_ext_prec_float type (even though they should).  */
  1274.  
  1275.         if (!strcmp (name, "long double"))
  1276.           return FT_ext_prec_float;
  1277.       }
  1278.  
  1279.     if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
  1280.       return FT_dbl_prec_float;
  1281.     if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
  1282.       return FT_float;
  1283.  
  1284.     /* Note that here we can run afowl of a serious bug in "classic"
  1285.        svr4 SDB debuggers.  They don't seem to understand the
  1286.        FT_ext_prec_float type (even though they should).  */
  1287.  
  1288.     if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
  1289.       return FT_ext_prec_float;
  1290.     abort ();
  1291.  
  1292.       case COMPLEX_TYPE:
  1293.     return FT_complex;    /* GNU FORTRAN COMPLEX type.  */
  1294.  
  1295.       case CHAR_TYPE:
  1296.     return FT_char;        /* GNU Pascal CHAR type.  Not used in C.  */
  1297.  
  1298.       case BOOLEAN_TYPE:
  1299.     return FT_boolean;    /* GNU FORTRAN BOOLEAN type.  */
  1300.  
  1301.       default:
  1302.     abort ();    /* No other TREE_CODEs are Dwarf fundamental types.  */
  1303.     }
  1304.   return 0;
  1305. }
  1306.  
  1307. /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
  1308.    the Dwarf "root" type for the given input type.  The Dwarf "root" type
  1309.    of a given type is generally the same as the given type, except that if
  1310.    the    given type is a pointer or reference type, then the root type of
  1311.    the given type is the root type of the "basis" type for the pointer or
  1312.    reference type.  (This definition of the "root" type is recursive.)
  1313.    Also, the root type of a `const' qualified type or a `volatile'
  1314.    qualified type is the root type of the given type without the
  1315.    qualifiers.  */
  1316.  
  1317. static tree
  1318. root_type (type)
  1319.      register tree type;
  1320. {
  1321.   if (TREE_CODE (type) == ERROR_MARK)
  1322.     return error_mark_node;
  1323.  
  1324.   switch (TREE_CODE (type))
  1325.     {
  1326.       case ERROR_MARK:
  1327.     return error_mark_node;
  1328.  
  1329.       case POINTER_TYPE:
  1330.       case REFERENCE_TYPE:
  1331.     return type_main_variant (root_type (TREE_TYPE (type)));
  1332.  
  1333.       default:
  1334.     return type_main_variant (type);
  1335.     }
  1336. }
  1337.  
  1338. /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
  1339.    of zero or more Dwarf "type-modifier" bytes applicable to the type.    */
  1340.  
  1341. static void
  1342. write_modifier_bytes (type, decl_const, decl_volatile)
  1343.      register tree type;
  1344.      register int decl_const;
  1345.      register int decl_volatile;
  1346. {
  1347.   if (TREE_CODE (type) == ERROR_MARK)
  1348.     return;
  1349.  
  1350.   if (TYPE_READONLY (type) || decl_const)
  1351.     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const);
  1352.   if (TYPE_VOLATILE (type) || decl_volatile)
  1353.     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile);
  1354.   switch (TREE_CODE (type))
  1355.     {
  1356.       case POINTER_TYPE:
  1357.     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to);
  1358.     write_modifier_bytes (TREE_TYPE (type), 0, 0);
  1359.     return;
  1360.  
  1361.       case REFERENCE_TYPE:
  1362.     ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to);
  1363.     write_modifier_bytes (TREE_TYPE (type), 0, 0);
  1364.     return;
  1365.  
  1366.       case ERROR_MARK:
  1367.       default:
  1368.     return;
  1369.     }
  1370. }
  1371.  
  1372. /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
  1373.    given input type is a Dwarf "fundamental" type.  Otherwise return zero.  */
  1374.  
  1375. inline int
  1376. type_is_fundamental (type)
  1377.      register tree type;
  1378. {
  1379.   switch (TREE_CODE (type))
  1380.     {
  1381.       case ERROR_MARK:
  1382.       case VOID_TYPE:
  1383.       case INTEGER_TYPE:
  1384.       case REAL_TYPE:
  1385.       case COMPLEX_TYPE:
  1386.       case BOOLEAN_TYPE:
  1387.       case CHAR_TYPE:
  1388.     return 1;
  1389.  
  1390.       case SET_TYPE:
  1391.       case ARRAY_TYPE:
  1392.       case RECORD_TYPE:
  1393.       case UNION_TYPE:
  1394.       case QUAL_UNION_TYPE:
  1395.       case ENUMERAL_TYPE:
  1396.       case FUNCTION_TYPE:
  1397.       case METHOD_TYPE:
  1398.       case POINTER_TYPE:
  1399.       case REFERENCE_TYPE:
  1400.       case FILE_TYPE:
  1401.       case OFFSET_TYPE:
  1402.       case LANG_TYPE:
  1403.     return 0;
  1404.  
  1405.       default:
  1406.     abort ();
  1407.     }
  1408.   return 0;
  1409. }
  1410.  
  1411. /* Given a pointer to some ..._DECL tree node, generate an assembly language
  1412.    equate directive which will associate a symbolic name with the current DIE.
  1413.  
  1414.    The name used is an artificial label generated from the DECL_UID number
  1415.    associated with the given decl node.  The name it gets equated to is the
  1416.    symbolic label that we (previously) output at the start of the DIE that
  1417.    we are currently generating.
  1418.  
  1419.    Calling this function while generating some "decl related" form of DIE
  1420.    makes it possible to later refer to the DIE which represents the given
  1421.    decl simply by re-generating the symbolic name from the ..._DECL node's
  1422.    UID number.    */
  1423.  
  1424. static void
  1425. equate_decl_number_to_die_number (decl)
  1426.      register tree decl;
  1427. {
  1428.   /* In the case where we are generating a DIE for some ..._DECL node
  1429.      which represents either some inline function declaration or some
  1430.      entity declared within an inline function declaration/definition,
  1431.      setup a symbolic name for the current DIE so that we have a name
  1432.      for this DIE that we can easily refer to later on within
  1433.      AT_abstract_origin attributes.  */
  1434.  
  1435.   char decl_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1436.   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1437.  
  1438.   sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl));
  1439.   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  1440.   ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label);
  1441. }
  1442.  
  1443. /* Given a pointer to some ..._TYPE tree node, generate an assembly language
  1444.    equate directive which will associate a symbolic name with the current DIE.
  1445.  
  1446.    The name used is an artificial label generated from the TYPE_UID number
  1447.    associated with the given type node.  The name it gets equated to is the
  1448.    symbolic label that we (previously) output at the start of the DIE that
  1449.    we are currently generating.
  1450.  
  1451.    Calling this function while generating some "type related" form of DIE
  1452.    makes it easy to later refer to the DIE which represents the given type
  1453.    simply by re-generating the alternative name from the ..._TYPE node's
  1454.    UID number.    */
  1455.  
  1456. inline void
  1457. equate_type_number_to_die_number (type)
  1458.      register tree type;
  1459. {
  1460.   char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1461.   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1462.  
  1463.   /* We are generating a DIE to represent the main variant of this type
  1464.      (i.e the type without any const or volatile qualifiers) so in order
  1465.      to get the equate to come out right, we need to get the main variant
  1466.      itself here.  */
  1467.  
  1468.   type = type_main_variant (type);
  1469.  
  1470.   sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type));
  1471.   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  1472.   ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
  1473. }
  1474.  
  1475. static void
  1476. output_reg_number (rtl)
  1477.      register rtx rtl;
  1478. {
  1479.   register unsigned regno = REGNO (rtl);
  1480.  
  1481.   if (regno >= FIRST_PSEUDO_REGISTER)
  1482.     {
  1483.       warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
  1484.              regno);
  1485.       regno = 0;
  1486.     }
  1487.   fprintf (asm_out_file, "\t%s\t0x%x",
  1488.        UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno));
  1489.   if (flag_verbose_asm)
  1490.     {
  1491.       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
  1492.       PRINT_REG (rtl, 0, asm_out_file);
  1493.     }
  1494.   fputc ('\n', asm_out_file);
  1495. }
  1496.  
  1497. /* The following routine is a nice and simple transducer.  It converts the
  1498.    RTL for a variable or parameter (resident in memory) into an equivalent
  1499.    Dwarf representation of a mechanism for getting the address of that same
  1500.    variable onto the top of a hypothetical "address evaluation" stack.
  1501.  
  1502.    When creating memory location descriptors, we are effectively trans-
  1503.    forming the RTL for a memory-resident object into its Dwarf postfix
  1504.    expression equivalent.  This routine just recursively descends an
  1505.    RTL tree, turning it into Dwarf postfix code as it goes.  */
  1506.  
  1507. static void
  1508. output_mem_loc_descriptor (rtl)
  1509.       register rtx rtl;
  1510. {
  1511.   /* Note that for a dynamically sized array, the location we will
  1512.      generate a description of here will be the lowest numbered location
  1513.      which is actually within the array.  That's *not* necessarily the
  1514.      same as the zeroth element of the array.  */
  1515.  
  1516.   switch (GET_CODE (rtl))
  1517.     {
  1518.       case SUBREG:
  1519.  
  1520.     /* The case of a subreg may arise when we have a local (register)
  1521.        variable or a formal (register) parameter which doesn't quite
  1522.        fill up an entire register.    For now, just assume that it is
  1523.        legitimate to make the Dwarf info refer to the whole register
  1524.        which contains the given subreg.  */
  1525.  
  1526.     rtl = XEXP (rtl, 0);
  1527.     /* Drop thru.  */
  1528.  
  1529.       case REG:
  1530.  
  1531.     /* Whenever a register number forms a part of the description of
  1532.        the method for calculating the (dynamic) address of a memory
  1533.        resident object, DWARF rules require the register number to
  1534.        be referred to as a "base register".  This distinction is not
  1535.        based in any way upon what category of register the hardware
  1536.        believes the given register belongs to.  This is strictly
  1537.        DWARF terminology we're dealing with here.
  1538.  
  1539.        Note that in cases where the location of a memory-resident data
  1540.        object could be expressed as:
  1541.  
  1542.             OP_ADD (OP_BASEREG (basereg), OP_CONST (0))
  1543.  
  1544.        the actual DWARF location descriptor that we generate may just
  1545.        be OP_BASEREG (basereg).  This may look deceptively like the
  1546.        object in question was allocated to a register (rather than
  1547.        in memory) so DWARF consumers need to be aware of the subtle
  1548.        distinction between OP_REG and OP_BASEREG.  */
  1549.  
  1550.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG);
  1551.     output_reg_number (rtl);
  1552.     break;
  1553.  
  1554.       case MEM:
  1555.     output_mem_loc_descriptor (XEXP (rtl, 0));
  1556.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4);
  1557.     break;
  1558.  
  1559.       case CONST:
  1560.       case SYMBOL_REF:
  1561.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR);
  1562.     ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
  1563.     break;
  1564.  
  1565.       case PLUS:
  1566.     output_mem_loc_descriptor (XEXP (rtl, 0));
  1567.     output_mem_loc_descriptor (XEXP (rtl, 1));
  1568.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
  1569.     break;
  1570.  
  1571.       case CONST_INT:
  1572.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
  1573.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
  1574.     break;
  1575.  
  1576.       default:
  1577.     abort ();
  1578.     }
  1579. }
  1580.  
  1581. /* Output a proper Dwarf location descriptor for a variable or parameter
  1582.    which is either allocated in a register or in a memory location.  For
  1583.    a register, we just generate an OP_REG and the register number.  For a
  1584.    memory location we provide a Dwarf postfix expression describing how to
  1585.    generate the (dynamic) address of the object onto the address stack.  */
  1586.  
  1587. static void
  1588. output_loc_descriptor (rtl)
  1589.      register rtx rtl;
  1590. {
  1591.   switch (GET_CODE (rtl))
  1592.     {
  1593.     case SUBREG:
  1594.  
  1595.     /* The case of a subreg may arise when we have a local (register)
  1596.        variable or a formal (register) parameter which doesn't quite
  1597.        fill up an entire register.    For now, just assume that it is
  1598.        legitimate to make the Dwarf info refer to the whole register
  1599.        which contains the given subreg.  */
  1600.  
  1601.     rtl = XEXP (rtl, 0);
  1602.     /* Drop thru.  */
  1603.  
  1604.     case REG:
  1605.     ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG);
  1606.     output_reg_number (rtl);
  1607.     break;
  1608.  
  1609.     case MEM:
  1610.       output_mem_loc_descriptor (XEXP (rtl, 0));
  1611.       break;
  1612.  
  1613.     default:
  1614.       abort ();        /* Should never happen */
  1615.     }
  1616. }
  1617.  
  1618. /* Given a tree node describing an array bound (either lower or upper)
  1619.    output a representation for that bound.  */
  1620.  
  1621. static void
  1622. output_bound_representation (bound, dim_num, u_or_l)
  1623.      register tree bound;
  1624.      register unsigned dim_num; /* For multi-dimensional arrays.  */
  1625.      register char u_or_l;    /* Designates upper or lower bound.  */
  1626. {
  1627.   switch (TREE_CODE (bound))
  1628.     {
  1629.  
  1630.       case ERROR_MARK:
  1631.     return;
  1632.  
  1633.       /* All fixed-bounds are represented by INTEGER_CST nodes.     */
  1634.  
  1635.       case INTEGER_CST:
  1636.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  1637.                 (unsigned) TREE_INT_CST_LOW (bound));
  1638.     break;
  1639.  
  1640.       /* Dynamic bounds may be represented by NOP_EXPR nodes containing
  1641.      SAVE_EXPR nodes.  */
  1642.  
  1643.       case NOP_EXPR:
  1644.     bound = TREE_OPERAND (bound, 0);
  1645.     /* ... fall thru... */
  1646.  
  1647.       case SAVE_EXPR:
  1648.     {
  1649.       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1650.       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1651.  
  1652.       sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
  1653.                 current_dienum, dim_num, u_or_l);
  1654.  
  1655.       sprintf (end_label,    BOUND_END_LABEL_FMT,
  1656.                 current_dienum, dim_num, u_or_l);
  1657.  
  1658.       ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  1659.       ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1660.  
  1661.       /* If we are working on a bound for a dynamic dimension in C,
  1662.          the dynamic dimension in question had better have a static
  1663.          (zero) lower bound and a dynamic *upper* bound.  */
  1664.  
  1665.       if (u_or_l != 'u')
  1666.         abort ();
  1667.  
  1668.       /* If optimization is turned on, the SAVE_EXPRs that describe
  1669.          how to access the upper bound values are essentially bogus.
  1670.          They only describe (at best) how to get at these values at
  1671.          the points in the generated code right after they have just
  1672.          been computed.  Worse yet, in the typical case, the upper
  1673.          bound values will not even *be* computed in the optimized
  1674.          code, so these SAVE_EXPRs are entirely bogus.
  1675.  
  1676.          In order to compensate for this fact, we check here to see
  1677.          if optimization is enabled, and if so, we effectively create
  1678.          an empty location description for the (unknown and unknowable)
  1679.          upper bound.
  1680.  
  1681.          This should not cause too much trouble for existing (stupid?)
  1682.          debuggers because they have to deal with empty upper bounds
  1683.          location descriptions anyway in order to be able to deal with
  1684.          incomplete array types.
  1685.  
  1686.          Of course an intelligent debugger (GDB?) should be able to
  1687.          comprehend that a missing upper bound specification in a
  1688.          array type used for a storage class `auto' local array variable
  1689.          indicates that the upper bound is both unknown (at compile-
  1690.          time) and unknowable (at run-time) due to optimization.
  1691.       */
  1692.  
  1693.       if (! optimize)
  1694.         output_loc_descriptor
  1695.           (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX));
  1696.  
  1697.       ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1698.     }
  1699.     break;
  1700.  
  1701.       default:
  1702.     abort ();
  1703.     }
  1704. }
  1705.  
  1706. /* Recursive function to output a sequence of value/name pairs for
  1707.    enumeration constants in reversed order.  This is called from
  1708.    enumeration_type_die.  */
  1709.  
  1710. static void
  1711. output_enumeral_list (link)
  1712.      register tree link;
  1713. {
  1714.   if (link)
  1715.     {
  1716.       output_enumeral_list (TREE_CHAIN (link));
  1717.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  1718.                   (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
  1719.       ASM_OUTPUT_DWARF_STRING (asm_out_file,
  1720.                    IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  1721.     }
  1722. }
  1723.  
  1724. /* Given an unsigned value, round it up to the lowest multiple of `boundary'
  1725.    which is not less than the value itself.  */
  1726.  
  1727. inline unsigned
  1728. ceiling (value, boundary)
  1729.      register unsigned value;
  1730.      register unsigned boundary;
  1731. {
  1732.   return (((value + boundary - 1) / boundary) * boundary);
  1733. }
  1734.  
  1735. /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
  1736.    pointer to the declared type for the relevant field variable, or return
  1737.    `integer_type_node' if the given node turns out to be an ERROR_MARK node.  */
  1738.  
  1739. inline tree
  1740. field_type (decl)
  1741.      register tree decl;
  1742. {
  1743.   register tree type;
  1744.  
  1745.   if (TREE_CODE (decl) == ERROR_MARK)
  1746.     return integer_type_node;
  1747.  
  1748.   type = DECL_BIT_FIELD_TYPE (decl);
  1749.   if (type == NULL)
  1750.     type = TREE_TYPE (decl);
  1751.   return type;
  1752. }
  1753.  
  1754. /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
  1755.    node, return the alignment in bits for the type, or else return
  1756.    BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node.  */
  1757.  
  1758. inline unsigned
  1759. simple_type_align_in_bits (type)
  1760.      register tree type;
  1761. {
  1762.   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
  1763. }
  1764.  
  1765. /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
  1766.    node, return the size in bits for the type if it is a constant, or
  1767.    else return the alignment for the type if the type's size is not
  1768.    constant, or else return BITS_PER_WORD if the type actually turns out
  1769.    to be an ERROR_MARK node.  */
  1770.  
  1771. inline unsigned
  1772. simple_type_size_in_bits (type)
  1773.      register tree type;
  1774. {
  1775.   if (TREE_CODE (type) == ERROR_MARK)
  1776.     return BITS_PER_WORD;
  1777.   else
  1778.     {
  1779.       register tree type_size_tree = TYPE_SIZE (type);
  1780.  
  1781.       if (TREE_CODE (type_size_tree) != INTEGER_CST)
  1782.     return TYPE_ALIGN (type);
  1783.  
  1784.       return (unsigned) TREE_INT_CST_LOW (type_size_tree);
  1785.     }
  1786. }
  1787.  
  1788. /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
  1789.    return the byte offset of the lowest addressed byte of the "containing
  1790.    object" for the given FIELD_DECL, or return 0 if we are unable to deter-
  1791.    mine what that offset is, either because the argument turns out to be a
  1792.    pointer to an ERROR_MARK node, or because the offset is actually variable.
  1793.    (We can't handle the latter case just yet.)  */
  1794.  
  1795. static unsigned
  1796. field_byte_offset (decl)
  1797.      register tree decl;
  1798. {
  1799.   register unsigned type_align_in_bytes;
  1800.   register unsigned type_align_in_bits;
  1801.   register unsigned type_size_in_bits;
  1802.   register unsigned object_offset_in_align_units;
  1803.   register unsigned object_offset_in_bits;
  1804.   register unsigned object_offset_in_bytes;
  1805.   register tree type;
  1806.   register tree bitpos_tree;
  1807.   register tree field_size_tree;
  1808.   register unsigned bitpos_int;
  1809.   register unsigned deepest_bitpos;
  1810.   register unsigned field_size_in_bits;
  1811.  
  1812.   if (TREE_CODE (decl) == ERROR_MARK)
  1813.     return 0;
  1814.  
  1815.   if (TREE_CODE (decl) != FIELD_DECL)
  1816.     abort ();
  1817.  
  1818.   type = field_type (decl);
  1819.  
  1820.   bitpos_tree = DECL_FIELD_BITPOS (decl);
  1821.   field_size_tree = DECL_SIZE (decl);
  1822.  
  1823.   /* We cannot yet cope with fields whose positions or sizes are variable,
  1824.      so for now, when we see such things, we simply return 0.  Someday,
  1825.      we may be able to handle such cases, but it will be damn difficult.  */
  1826.  
  1827.   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
  1828.     return 0;
  1829.   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
  1830.  
  1831.   if (TREE_CODE (field_size_tree) != INTEGER_CST)
  1832.     return 0;
  1833.   field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
  1834.  
  1835.   type_size_in_bits = simple_type_size_in_bits (type);
  1836.  
  1837.   type_align_in_bits = simple_type_align_in_bits (type);
  1838.   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
  1839.  
  1840.   /* Note that the GCC front-end doesn't make any attempt to keep track
  1841.      of the starting bit offset (relative to the start of the containing
  1842.      structure type) of the hypothetical "containing object" for a bit-
  1843.      field.  Thus, when computing the byte offset value for the start of
  1844.      the "containing object" of a bit-field, we must deduce this infor-
  1845.      mation on our own.
  1846.  
  1847.      This can be rather tricky to do in some cases.  For example, handling
  1848.      the following structure type definition when compiling for an i386/i486
  1849.      target (which only aligns long long's to 32-bit boundaries) can be very
  1850.      tricky:
  1851.  
  1852.         struct S {
  1853.             int        field1;
  1854.             long long    field2:31;
  1855.         };
  1856.  
  1857.      Fortunately, there is a simple rule-of-thumb which can be used in such
  1858.      cases.  When compiling for an i386/i486, GCC will allocate 8 bytes for
  1859.      the structure shown above.  It decides to do this based upon one simple
  1860.      rule for bit-field allocation.  Quite simply, GCC allocates each "con-
  1861.      taining object" for each bit-field at the first (i.e. lowest addressed)
  1862.      legitimate alignment boundary (based upon the required minimum alignment
  1863.      for the declared type of the field) which it can possibly use, subject
  1864.      to the condition that there is still enough available space remaining
  1865.      in the containing object (when allocated at the selected point) to
  1866.      fully accommodate all of the bits of the bit-field itself.
  1867.  
  1868.      This simple rule makes it obvious why GCC allocates 8 bytes for each
  1869.      object of the structure type shown above.  When looking for a place to
  1870.      allocate the "containing object" for `field2', the compiler simply tries
  1871.      to allocate a 64-bit "containing object" at each successive 32-bit
  1872.      boundary (starting at zero) until it finds a place to allocate that 64-
  1873.      bit field such that at least 31 contiguous (and previously unallocated)
  1874.      bits remain within that selected 64 bit field.  (As it turns out, for
  1875.      the example above, the compiler finds that it is OK to allocate the
  1876.      "containing object" 64-bit field at bit-offset zero within the
  1877.      structure type.)
  1878.  
  1879.      Here we attempt to work backwards from the limited set of facts we're
  1880.      given, and we try to deduce from those facts, where GCC must have
  1881.      believed that the containing object started (within the structure type).
  1882.  
  1883.      The value we deduce is then used (by the callers of this routine) to
  1884.      generate AT_location and AT_bit_offset attributes for fields (both
  1885.      bit-fields and, in the case of AT_location, regular fields as well).
  1886.   */
  1887.  
  1888.   /* Figure out the bit-distance from the start of the structure to the
  1889.      "deepest" bit of the bit-field.  */
  1890.   deepest_bitpos = bitpos_int + field_size_in_bits;
  1891.  
  1892.   /* This is the tricky part.  Use some fancy footwork to deduce where the
  1893.      lowest addressed bit of the containing object must be.  */
  1894.   object_offset_in_bits
  1895.     = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
  1896.  
  1897.   /* Compute the offset of the containing object in "alignment units".  */
  1898.   object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
  1899.  
  1900.   /* Compute the offset of the containing object in bytes.  */
  1901.   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
  1902.  
  1903.   return object_offset_in_bytes;
  1904. }
  1905.  
  1906. /****************************** attributes *********************************/
  1907.  
  1908. /* The following routines are responsible for writing out the various types
  1909.    of Dwarf attributes (and any following data bytes associated with them).
  1910.    These routines are listed in order based on the numerical codes of their
  1911.    associated attributes.  */
  1912.  
  1913. /* Generate an AT_sibling attribute.  */
  1914.  
  1915. inline void
  1916. sibling_attribute ()
  1917. {
  1918.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1919.  
  1920.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
  1921.   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
  1922.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  1923. }
  1924.  
  1925. /* Output the form of location attributes suitable for whole variables and
  1926.    whole parameters.  Note that the location attributes for struct fields
  1927.    are generated by the routine `data_member_location_attribute' below.  */
  1928.  
  1929. static void
  1930. location_attribute (rtl)
  1931.      register rtx rtl;
  1932. {
  1933.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1934.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1935.  
  1936.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
  1937.   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
  1938.   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
  1939.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  1940.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1941.  
  1942.   /* Handle a special case.  If we are about to output a location descriptor
  1943.      for a variable or parameter which has been optimized out of existence,
  1944.      don't do that.  Instead we output a zero-length location descriptor
  1945.      value as part of the location attribute.
  1946.  
  1947.      A variable which has been optimized out of existence will have a
  1948.      DECL_RTL value which denotes a pseudo-reg.
  1949.  
  1950.      Currently, in some rare cases, variables can have DECL_RTL values
  1951.      which look like (MEM (REG pseudo-reg#)).  These cases are due to
  1952.      bugs elsewhere in the compiler.  We treat such cases
  1953.      as if the variable(s) in question had been optimized out of existence.
  1954.  
  1955.      Note that in all cases where we wish to express the fact that a
  1956.      variable has been optimized out of existence, we do not simply
  1957.      suppress the generation of the entire location attribute because
  1958.      the absence of a location attribute in certain kinds of DIEs is
  1959.      used to indicate something else entirely... i.e. that the DIE
  1960.      represents an object declaration, but not a definition.  So sayeth
  1961.      the PLSIG.
  1962.   */
  1963.  
  1964.   if (! is_pseudo_reg (rtl)
  1965.       && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0))))
  1966.     output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX));
  1967.  
  1968.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1969. }
  1970.  
  1971. /* Output the specialized form of location attribute used for data members
  1972.    of struct and union types.
  1973.  
  1974.    In the special case of a FIELD_DECL node which represents a bit-field,
  1975.    the "offset" part of this special location descriptor must indicate the
  1976.    distance in bytes from the lowest-addressed byte of the containing
  1977.    struct or union type to the lowest-addressed byte of the "containing
  1978.    object" for the bit-field.  (See the `field_byte_offset' function above.)
  1979.  
  1980.    For any given bit-field, the "containing object" is a hypothetical
  1981.    object (of some integral or enum type) within which the given bit-field
  1982.    lives.  The type of this hypothetical "containing object" is always the
  1983.    same as the declared type of the individual bit-field itself (for GCC
  1984.    anyway... the DWARF spec doesn't actually mandate this).
  1985.  
  1986.    Note that it is the size (in bytes) of the hypothetical "containing
  1987.    object" which will be given in the AT_byte_size attribute for this
  1988.    bit-field.  (See the `byte_size_attribute' function below.)  It is
  1989.    also used when calculating the value of the AT_bit_offset attribute.
  1990.    (See the `bit_offset_attribute' function below.)
  1991. */
  1992.  
  1993. static void
  1994. data_member_location_attribute (decl)
  1995.      register tree decl;
  1996. {
  1997.   register unsigned object_offset_in_bytes = field_byte_offset (decl);
  1998.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1999.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2000.  
  2001.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
  2002.   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
  2003.   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
  2004.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  2005.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2006.   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST);
  2007.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes);
  2008.   ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD);
  2009.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2010. }
  2011.  
  2012. /* Output an AT_const_value attribute for a variable or a parameter which
  2013.    does not have a "location" either in memory or in a register.  These
  2014.    things can arise in GNU C when a constant is passed as an actual
  2015.    parameter to an inlined function.  They can also arise in C++ where
  2016.    declared constants do not necessarily get memory "homes".  */
  2017.  
  2018. static void
  2019. const_value_attribute (rtl)
  2020.      register rtx rtl;
  2021. {
  2022.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2023.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2024.  
  2025.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4);
  2026.   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
  2027.   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
  2028.   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
  2029.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2030.  
  2031.   switch (GET_CODE (rtl))
  2032.     {
  2033.       case CONST_INT:
  2034.     /* Note that a CONST_INT rtx could represent either an integer or
  2035.        a floating-point constant.  A CONST_INT is used whenever the
  2036.        constant will fit into a single word.  In all such cases, the
  2037.        original mode of the constant value is wiped out, and the
  2038.        CONST_INT rtx is assigned VOIDmode.  Since we no longer have
  2039.        precise mode information for these constants, we always just
  2040.        output them using 4 bytes.  */
  2041.  
  2042.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl));
  2043.     break;
  2044.  
  2045.       case CONST_DOUBLE:
  2046.     /* Note that a CONST_DOUBLE rtx could represent either an integer
  2047.        or a floating-point constant.  A CONST_DOUBLE is used whenever
  2048.        the constant requires more than one word in order to be adequately
  2049.        represented.  In all such cases, the original mode of the constant
  2050.        value is preserved as the mode of the CONST_DOUBLE rtx, but for
  2051.        simplicity we always just output CONST_DOUBLEs using 8 bytes.  */
  2052.  
  2053.     ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
  2054.                 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl),
  2055.                 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl));
  2056.     break;
  2057.  
  2058.       case CONST_STRING:
  2059.     ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0));
  2060.     break;
  2061.  
  2062.       case SYMBOL_REF:
  2063.       case LABEL_REF:
  2064.       case CONST:
  2065.     ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
  2066.     break;
  2067.  
  2068.       case PLUS:
  2069.     /* In cases where an inlined instance of an inline function is passed
  2070.        the address of an `auto' variable (which is local to the caller)
  2071.        we can get a situation where the DECL_RTL of the artificial
  2072.        local variable (for the inlining) which acts as a stand-in for
  2073.        the corresponding formal parameter (of the inline function)
  2074.        will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).
  2075.        This is not exactly a compile-time constant expression, but it
  2076.        isn't the address of the (artificial) local variable either.
  2077.        Rather, it represents the *value* which the artificial local
  2078.        variable always has during its lifetime.  We currently have no
  2079.        way to represent such quasi-constant values in Dwarf, so for now
  2080.        we just punt and generate an AT_const_value attribute with form
  2081.        FORM_BLOCK4 and a length of zero.  */
  2082.     break;
  2083.  
  2084.       default:
  2085.     abort ();  /* No other kinds of rtx should be possible here.  */
  2086.     }
  2087.  
  2088.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2089. }
  2090.  
  2091. /* Generate *either* an AT_location attribute or else an AT_const_value
  2092.    data attribute for a variable or a parameter.  We generate the
  2093.    AT_const_value attribute only in those cases where the given
  2094.    variable or parameter does not have a true "location" either in
  2095.    memory or in a register.  This can happen (for example) when a
  2096.    constant is passed as an actual argument in a call to an inline
  2097.    function.  (It's possible that these things can crop up in other
  2098.    ways also.)  Note that one type of constant value which can be
  2099.    passed into an inlined function is a constant pointer.  This can
  2100.    happen for example if an actual argument in an inlined function
  2101.    call evaluates to a compile-time constant address.  */
  2102.  
  2103. static void
  2104. location_or_const_value_attribute (decl)
  2105.      register tree decl;
  2106. {
  2107.   register rtx rtl;
  2108.  
  2109.   if (TREE_CODE (decl) == ERROR_MARK)
  2110.     return;
  2111.  
  2112.   if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL))
  2113.     {
  2114.       /* Should never happen.  */
  2115.       abort ();
  2116.       return;
  2117.     }
  2118.  
  2119.   /* Here we have to decide where we are going to say the parameter "lives"
  2120.      (as far as the debugger is concerned).  We only have a couple of choices.
  2121.      GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.  DECL_RTL
  2122.      normally indicates where the parameter lives during most of the activa-
  2123.      tion of the function.  If optimization is enabled however, this could
  2124.      be either NULL or else a pseudo-reg.  Both of those cases indicate that
  2125.      the parameter doesn't really live anywhere (as far as the code generation
  2126.      parts of GCC are concerned) during most of the function's activation.
  2127.      That will happen (for example) if the parameter is never referenced
  2128.      within the function.
  2129.  
  2130.      We could just generate a location descriptor here for all non-NULL
  2131.      non-pseudo values of DECL_RTL and ignore all of the rest, but we can
  2132.      be a little nicer than that if we also consider DECL_INCOMING_RTL in
  2133.      cases where DECL_RTL is NULL or is a pseudo-reg.
  2134.  
  2135.      Note however that we can only get away with using DECL_INCOMING_RTL as
  2136.      a backup substitute for DECL_RTL in certain limited cases.  In cases
  2137.      where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl)
  2138.      we can be sure that the parameter was passed using the same type as it
  2139.      is declared to have within the function, and that its DECL_INCOMING_RTL
  2140.      points us to a place where a value of that type is passed.  In cases
  2141.      where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types
  2142.      however, we cannot (in general) use DECL_INCOMING_RTL as a backup
  2143.      substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL
  2144.      points us to a value of some type which is *different* from the type
  2145.      of the parameter itself.  Thus, if we tried to use DECL_INCOMING_RTL
  2146.      to generate a location attribute in such cases, the debugger would
  2147.      end up (for example) trying to fetch a `float' from a place which
  2148.      actually contains the first part of a `double'.  That would lead to
  2149.      really incorrect and confusing output at debug-time, and we don't
  2150.      want that now do we?
  2151.  
  2152.      So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL
  2153.      in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl).  There are a
  2154.      couple of cute exceptions however.  On little-endian machines we can
  2155.      get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is
  2156.      not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is
  2157.      an integral type which is smaller than TREE_TYPE(decl).  These cases
  2158.      arise when (on a little-endian machine) a non-prototyped function has
  2159.      a parameter declared to be of type `short' or `char'.  In such cases,
  2160.      TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be
  2161.      `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
  2162.      passed `int' value.  If the debugger then uses that address to fetch a
  2163.      `short' or a `char' (on a little-endian machine) the result will be the
  2164.      correct data, so we allow for such exceptional cases below.
  2165.  
  2166.      Note that our goal here is to describe the place where the given formal
  2167.      parameter lives during most of the function's activation (i.e. between
  2168.      the end of the prologue and the start of the epilogue).  We'll do that
  2169.      as best as we can.  Note however that if the given formal parameter is
  2170.      modified sometime during the execution of the function, then a stack
  2171.      backtrace (at debug-time) will show the function as having been called
  2172.      with the *new* value rather than the value which was originally passed
  2173.      in.  This happens rarely enough that it is not a major problem, but it
  2174.      *is* a problem, and I'd like to fix it.  A future version of dwarfout.c
  2175.      may generate two additional attributes for any given TAG_formal_parameter
  2176.      DIE which will describe the "passed type" and the "passed location" for
  2177.      the given formal parameter in addition to the attributes we now generate
  2178.      to indicate the "declared type" and the "active location" for each
  2179.      parameter.  This additional set of attributes could be used by debuggers
  2180.      for stack backtraces.
  2181.  
  2182.      Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL
  2183.      can be NULL also.  This happens (for example) for inlined-instances of
  2184.      inline function formal parameters which are never referenced.  This really
  2185.      shouldn't be happening.  All PARM_DECL nodes should get valid non-NULL
  2186.      DECL_INCOMING_RTL values, but integrate.c doesn't currently generate
  2187.      these values for inlined instances of inline function parameters, so
  2188.      when we see such cases, we are just SOL (shit-out-of-luck) for the time
  2189.      being (until integrate.c gets fixed).
  2190.   */
  2191.  
  2192.   /* Use DECL_RTL as the "location" unless we find something better.  */
  2193.   rtl = DECL_RTL (decl);
  2194.  
  2195.   if (TREE_CODE (decl) == PARM_DECL)
  2196.     if (rtl == NULL_RTX || is_pseudo_reg (rtl))
  2197.       {
  2198.     /* This decl represents a formal parameter which was optimized out.  */
  2199.         register tree declared_type = type_main_variant (TREE_TYPE (decl));
  2200.         register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
  2201.  
  2202.     /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle
  2203.        *all* cases where (rtl == NULL_RTX) just below.  */
  2204.  
  2205.     if (declared_type == passed_type)
  2206.       rtl = DECL_INCOMING_RTL (decl);
  2207. #if (BYTES_BIG_ENDIAN == 0)
  2208.     else
  2209.       if (TREE_CODE (declared_type) == INTEGER_TYPE)
  2210.         if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
  2211.           rtl = DECL_INCOMING_RTL (decl);
  2212. #endif /* (BYTES_BIG_ENDIAN == 0) */
  2213.       }
  2214.  
  2215.   if (rtl == NULL_RTX)
  2216.     return;
  2217.  
  2218.   switch (GET_CODE (rtl))
  2219.     {
  2220.     case CONST_INT:
  2221.     case CONST_DOUBLE:
  2222.     case CONST_STRING:
  2223.     case SYMBOL_REF:
  2224.     case LABEL_REF:
  2225.     case CONST:
  2226.     case PLUS:    /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
  2227.       const_value_attribute (rtl);
  2228.       break;
  2229.  
  2230.     case MEM:
  2231.     case REG:
  2232.     case SUBREG:
  2233.       location_attribute (rtl);
  2234.       break;
  2235.  
  2236.     default:
  2237.       abort ();        /* Should never happen.  */
  2238.     }
  2239. }
  2240.  
  2241. /* Generate an AT_name attribute given some string value to be included as
  2242.    the value of the attribute.    */
  2243.  
  2244. inline void
  2245. name_attribute (name_string)
  2246.      register char *name_string;
  2247. {
  2248.   if (name_string && *name_string)
  2249.     {
  2250.       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
  2251.       ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
  2252.     }
  2253. }
  2254.  
  2255. inline void
  2256. fund_type_attribute (ft_code)
  2257.      register unsigned ft_code;
  2258. {
  2259.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
  2260.   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code);
  2261. }
  2262.  
  2263. static void
  2264. mod_fund_type_attribute (type, decl_const, decl_volatile)
  2265.      register tree type;
  2266.      register int decl_const;
  2267.      register int decl_volatile;
  2268. {
  2269.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2270.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2271.  
  2272.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
  2273.   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
  2274.   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
  2275.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  2276.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2277.   write_modifier_bytes (type, decl_const, decl_volatile);
  2278.   ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
  2279.                   fundamental_type_code (root_type (type)));
  2280.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2281. }
  2282.  
  2283. inline void
  2284. user_def_type_attribute (type)
  2285.      register tree type;
  2286. {
  2287.   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
  2288.  
  2289.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
  2290.   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type));
  2291.   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
  2292. }
  2293.  
  2294. static void
  2295. mod_u_d_type_attribute (type, decl_const, decl_volatile)
  2296.      register tree type;
  2297.      register int decl_const;
  2298.      register int decl_volatile;
  2299. {
  2300.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2301.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2302.   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
  2303.  
  2304.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
  2305.   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
  2306.   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
  2307.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  2308.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2309.   write_modifier_bytes (type, decl_const, decl_volatile);
  2310.   sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type)));
  2311.   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
  2312.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2313. }
  2314.  
  2315. #ifdef USE_ORDERING_ATTRIBUTE
  2316. inline void
  2317. ordering_attribute (ordering)
  2318.      register unsigned ordering;
  2319. {
  2320.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
  2321.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
  2322. }
  2323. #endif /* defined(USE_ORDERING_ATTRIBUTE) */
  2324.  
  2325. /* Note that the block of subscript information for an array type also
  2326.    includes information about the element type of type given array type.  */
  2327.  
  2328. static void
  2329. subscript_data_attribute (type)
  2330.      register tree type;
  2331. {
  2332.   register unsigned dimension_number;
  2333.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2334.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2335.  
  2336.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
  2337.   sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
  2338.   sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
  2339.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  2340.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2341.  
  2342.   /* The GNU compilers represent multidimensional array types as sequences
  2343.      of one dimensional array types whose element types are themselves array
  2344.      types.  Here we squish that down, so that each multidimensional array
  2345.      type gets only one array_type DIE in the Dwarf debugging info.  The
  2346.      draft Dwarf specification say that we are allowed to do this kind
  2347.      of compression in C (because there is no difference between an
  2348.      array or arrays and a multidimensional array in C) but for other
  2349.      source languages (e.g. Ada) we probably shouldn't do this.  */
  2350.  
  2351.   for (dimension_number = 0;
  2352.     TREE_CODE (type) == ARRAY_TYPE;
  2353.     type = TREE_TYPE (type), dimension_number++)
  2354.     {
  2355.       register tree domain = TYPE_DOMAIN (type);
  2356.  
  2357.       /* Arrays come in three flavors.    Unspecified bounds, fixed
  2358.      bounds, and (in GNU C only) variable bounds.  Handle all
  2359.      three forms here.  */
  2360.  
  2361.       if (domain)
  2362.     {
  2363.       /* We have an array type with specified bounds.  */
  2364.  
  2365.       register tree lower = TYPE_MIN_VALUE (domain);
  2366.       register tree upper = TYPE_MAX_VALUE (domain);
  2367.  
  2368.       /* Handle only fundamental types as index types for now.  */
  2369.  
  2370.       if (! type_is_fundamental (domain))
  2371.         abort ();
  2372.  
  2373.       /* Output the representation format byte for this dimension. */
  2374.  
  2375.       ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
  2376.                   FMT_CODE (1,
  2377.                         TREE_CODE (lower) == INTEGER_CST,
  2378.                         TREE_CODE (upper) == INTEGER_CST));
  2379.  
  2380.       /* Output the index type for this dimension.    */
  2381.  
  2382.       ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file,
  2383.                       fundamental_type_code (domain));
  2384.  
  2385.       /* Output the representation for the lower bound.  */
  2386.  
  2387.       output_bound_representation (lower, dimension_number, 'l');
  2388.  
  2389.       /* Output the representation for the upper bound.  */
  2390.  
  2391.       output_bound_representation (upper, dimension_number, 'u');
  2392.     }
  2393.       else
  2394.     {
  2395.       /* We have an array type with an unspecified length.    For C and
  2396.          C++ we can assume that this really means that (a) the index
  2397.          type is an integral type, and (b) the lower bound is zero.
  2398.          Note that Dwarf defines the representation of an unspecified
  2399.          (upper) bound as being a zero-length location description.     */
  2400.  
  2401.       /* Output the array-bounds format byte.  */
  2402.  
  2403.       ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X);
  2404.  
  2405.       /* Output the (assumed) index type.  */
  2406.  
  2407.       ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer);
  2408.  
  2409.       /* Output the (assumed) lower bound (constant) value.     */
  2410.  
  2411.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  2412.  
  2413.       /* Output the (empty) location description for the upper bound.  */
  2414.  
  2415.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
  2416.     }
  2417.     }
  2418.  
  2419.   /* Output the prefix byte that says that the element type is comming up.  */
  2420.  
  2421.   ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET);
  2422.  
  2423.   /* Output a representation of the type of the elements of this array type.  */
  2424.  
  2425.   type_attribute (type, 0, 0);
  2426.  
  2427.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2428. }
  2429.  
  2430. static void
  2431. byte_size_attribute (tree_node)
  2432.      register tree tree_node;
  2433. {
  2434.   register unsigned size;
  2435.  
  2436.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
  2437.   switch (TREE_CODE (tree_node))
  2438.     {
  2439.       case ERROR_MARK:
  2440.     size = 0;
  2441.     break;
  2442.  
  2443.       case ENUMERAL_TYPE:
  2444.       case RECORD_TYPE:
  2445.       case UNION_TYPE:
  2446.       case QUAL_UNION_TYPE:
  2447.     size = int_size_in_bytes (tree_node);
  2448.     break;
  2449.  
  2450.       case FIELD_DECL:
  2451.     /* For a data member of a struct or union, the AT_byte_size is
  2452.        generally given as the number of bytes normally allocated for
  2453.        an object of the *declared* type of the member itself.  This
  2454.        is true even for bit-fields.  */
  2455.     size = simple_type_size_in_bits (field_type (tree_node))
  2456.            / BITS_PER_UNIT;
  2457.     break;
  2458.  
  2459.       default:
  2460.     abort ();
  2461.     }
  2462.  
  2463.   /* Note that `size' might be -1 when we get to this point.  If it
  2464.      is, that indicates that the byte size of the entity in question
  2465.      is variable.  We have no good way of expressing this fact in Dwarf
  2466.      at the present time, so just let the -1 pass on through.  */
  2467.  
  2468.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
  2469. }
  2470.  
  2471. /* For a FIELD_DECL node which represents a bit-field, output an attribute
  2472.    which specifies the distance in bits from the highest order bit of the
  2473.    "containing object" for the bit-field to the highest order bit of the
  2474.    bit-field itself.
  2475.  
  2476.    For any given bit-field, the "containing object" is a hypothetical
  2477.    object (of some integral or enum type) within which the given bit-field
  2478.    lives.  The type of this hypothetical "containing object" is always the
  2479.    same as the declared type of the individual bit-field itself.
  2480.  
  2481.    The determination of the exact location of the "containing object" for
  2482.    a bit-field is rather complicated.  It's handled by the `field_byte_offset'
  2483.    function (above).
  2484.  
  2485.    Note that it is the size (in bytes) of the hypothetical "containing
  2486.    object" which will be given in the AT_byte_size attribute for this
  2487.    bit-field.  (See `byte_size_attribute' above.)
  2488. */
  2489.  
  2490. inline void
  2491. bit_offset_attribute (decl)
  2492.     register tree decl;
  2493. {
  2494.   register unsigned object_offset_in_bytes = field_byte_offset (decl);
  2495.   register tree type = DECL_BIT_FIELD_TYPE (decl);
  2496.   register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
  2497.   register unsigned bitpos_int;
  2498.   register unsigned highest_order_object_bit_offset;
  2499.   register unsigned highest_order_field_bit_offset;
  2500.   register unsigned bit_offset;
  2501.  
  2502.   assert (TREE_CODE (decl) == FIELD_DECL);    /* Must be a field.  */
  2503.   assert (type);                /* Must be a bit field.     */
  2504.  
  2505.   /* We can't yet handle bit-fields whose offsets are variable, so if we
  2506.      encounter such things, just return without generating any attribute
  2507.      whatsoever.  */
  2508.  
  2509.   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
  2510.     return;
  2511.   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
  2512.  
  2513.   /* Note that the bit offset is always the distance (in bits) from the
  2514.      highest-order bit of the "containing object" to the highest-order
  2515.      bit of the bit-field itself.  Since the "high-order end" of any
  2516.      object or field is different on big-endian and little-endian machines,
  2517.      the computation below must take account of these differences.  */
  2518.  
  2519.   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
  2520.   highest_order_field_bit_offset = bitpos_int;
  2521.  
  2522. #if (BYTES_BIG_ENDIAN == 0)
  2523.   highest_order_field_bit_offset
  2524.     += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
  2525.  
  2526.   highest_order_object_bit_offset += simple_type_size_in_bits (type);
  2527. #endif /* (BYTES_BIG_ENDIAN == 0) */
  2528.  
  2529.   bit_offset =
  2530. #if (BYTES_BIG_ENDIAN == 0)
  2531.       highest_order_object_bit_offset - highest_order_field_bit_offset;
  2532. #else /* (BYTES_BIG_ENDIAN != 0) */
  2533.       highest_order_field_bit_offset - highest_order_object_bit_offset;
  2534. #endif /* (BYTES_BIG_ENDIAN != 0) */
  2535.  
  2536.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
  2537.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset);
  2538. }
  2539.  
  2540. /* For a FIELD_DECL node which represents a bit field, output an attribute
  2541.    which specifies the length in bits of the given field.  */
  2542.  
  2543. inline void
  2544. bit_size_attribute (decl)
  2545.     register tree decl;
  2546. {
  2547.   assert (TREE_CODE (decl) == FIELD_DECL);    /* Must be a field.  */
  2548.   assert (DECL_BIT_FIELD_TYPE (decl));        /* Must be a bit field.     */
  2549.  
  2550.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
  2551.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  2552.               (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
  2553. }
  2554.  
  2555. /* The following routine outputs the `element_list' attribute for enumeration
  2556.    type DIEs.  The element_lits attribute includes the names and values of
  2557.    all of the enumeration constants associated with the given enumeration
  2558.    type.  */
  2559.  
  2560. inline void
  2561. element_list_attribute (element)
  2562.      register tree element;
  2563. {
  2564.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2565.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2566.  
  2567.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
  2568.   sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
  2569.   sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
  2570.   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
  2571.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2572.  
  2573.   /* Here we output a list of value/name pairs for each enumeration constant
  2574.      defined for this enumeration type (as required), but we do it in REVERSE
  2575.      order.  The order is the one required by the draft #5 Dwarf specification
  2576.      published by the UI/PLSIG.  */
  2577.  
  2578.   output_enumeral_list (element);   /* Recursively output the whole list.  */
  2579.  
  2580.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2581. }
  2582.  
  2583. /* Generate an AT_stmt_list attribute.    These are normally present only in
  2584.    DIEs with a TAG_compile_unit tag.  */
  2585.  
  2586. inline void
  2587. stmt_list_attribute (label)
  2588.     register char *label;
  2589. {
  2590.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
  2591.   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
  2592.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  2593. }
  2594.  
  2595. /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
  2596.    for a subroutine DIE.  */
  2597.  
  2598. inline void
  2599. low_pc_attribute (asm_low_label)
  2600.      register char *asm_low_label;
  2601. {
  2602.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
  2603.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
  2604. }
  2605.  
  2606. /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
  2607.    subroutine DIE.  */
  2608.  
  2609. inline void
  2610. high_pc_attribute (asm_high_label)
  2611.     register char *asm_high_label;
  2612. {
  2613.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
  2614.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
  2615. }
  2616.  
  2617. /* Generate an AT_body_begin attribute for a subroutine DIE.  */
  2618.  
  2619. inline void
  2620. body_begin_attribute (asm_begin_label)
  2621.      register char *asm_begin_label;
  2622. {
  2623.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin);
  2624.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label);
  2625. }
  2626.  
  2627. /* Generate an AT_body_end attribute for a subroutine DIE.  */
  2628.  
  2629. inline void
  2630. body_end_attribute (asm_end_label)
  2631.      register char *asm_end_label;
  2632. {
  2633.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end);
  2634.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label);
  2635. }
  2636.  
  2637. /* Generate an AT_language attribute given a LANG value.  These attributes
  2638.    are used only within TAG_compile_unit DIEs.  */
  2639.  
  2640. inline void
  2641. language_attribute (language_code)
  2642.      register unsigned language_code;
  2643. {
  2644.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
  2645.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code);
  2646. }
  2647.  
  2648. inline void
  2649. member_attribute (context)
  2650.     register tree context;
  2651. {
  2652.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  2653.  
  2654.   /* Generate this attribute only for members in C++.  */
  2655.  
  2656.   if (context != NULL && is_tagged_type (context))
  2657.     {
  2658.       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
  2659.       sprintf (label, TYPE_NAME_FMT, TYPE_UID (context));
  2660.       ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  2661.     }
  2662. }
  2663.  
  2664. inline void
  2665. string_length_attribute (upper_bound)
  2666.      register tree upper_bound;
  2667. {
  2668.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2669.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2670.  
  2671.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
  2672.   sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum);
  2673.   sprintf (end_label, SL_END_LABEL_FMT, current_dienum);
  2674.   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label);
  2675.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2676.   output_bound_representation (upper_bound, 0, 'u');
  2677.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2678. }
  2679.  
  2680. inline void
  2681. comp_dir_attribute (dirname)
  2682.      register char *dirname;
  2683. {
  2684.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
  2685.   ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
  2686. }
  2687.  
  2688. inline void
  2689. sf_names_attribute (sf_names_start_label)
  2690.      register char *sf_names_start_label;
  2691. {
  2692.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names);
  2693.   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
  2694.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label);
  2695. }
  2696.  
  2697. inline void
  2698. src_info_attribute (src_info_start_label)
  2699.      register char *src_info_start_label;
  2700. {
  2701.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
  2702.   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
  2703.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
  2704. }
  2705.  
  2706. inline void
  2707. mac_info_attribute (mac_info_start_label)
  2708.      register char *mac_info_start_label;
  2709. {
  2710.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info);
  2711.   /* Don't use ASM_OUTPUT_DWARF_DATA4 here.  */
  2712.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label);
  2713. }
  2714.  
  2715. inline void
  2716. prototyped_attribute (func_type)
  2717.      register tree func_type;
  2718. {
  2719.   if ((strcmp (language_string, "GNU C") == 0)
  2720.       && (TYPE_ARG_TYPES (func_type) != NULL))
  2721.     {
  2722.       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
  2723.       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
  2724.     }
  2725. }
  2726.  
  2727. inline void
  2728. producer_attribute (producer)
  2729.      register char *producer;
  2730. {
  2731.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer);
  2732.   ASM_OUTPUT_DWARF_STRING (asm_out_file, producer);
  2733. }
  2734.  
  2735. inline void
  2736. inline_attribute (decl)
  2737.      register tree decl;
  2738. {
  2739.   if (DECL_INLINE (decl))
  2740.     {
  2741.       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline);
  2742.       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
  2743.     }
  2744. }
  2745.  
  2746. inline void
  2747. containing_type_attribute (containing_type)
  2748.      register tree containing_type;
  2749. {
  2750.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  2751.  
  2752.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type);
  2753.   sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type));
  2754.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  2755. }
  2756.  
  2757. inline void
  2758. abstract_origin_attribute (origin)
  2759.      register tree origin;
  2760. {
  2761.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  2762.  
  2763.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin);
  2764.   switch (TREE_CODE_CLASS (TREE_CODE (origin)))
  2765.     {
  2766.     case 'd':
  2767.       sprintf (label, DECL_NAME_FMT, DECL_UID (origin));
  2768.       break;
  2769.  
  2770.     case 't':
  2771.       sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin));
  2772.       break;
  2773.  
  2774.     default:
  2775.       abort ();        /* Should never happen.  */
  2776.  
  2777.     }
  2778.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  2779. }
  2780.  
  2781. #ifdef DWARF_DECL_COORDINATES
  2782. inline void
  2783. src_coords_attribute (src_fileno, src_lineno)
  2784.      register unsigned src_fileno;
  2785.      register unsigned src_lineno;
  2786. {
  2787.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords);
  2788.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno);
  2789.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno);
  2790. }
  2791. #endif /* defined(DWARF_DECL_COORDINATES) */
  2792.  
  2793. inline void
  2794. pure_or_virtual_attribute (func_decl)
  2795.      register tree func_decl;
  2796. {
  2797.   if (DECL_VIRTUAL_P (func_decl))
  2798.     {
  2799. #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific.  */
  2800.       if (DECL_ABSTRACT_VIRTUAL_P (func_decl))
  2801.         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual);
  2802.       else
  2803. #endif
  2804.         ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual);
  2805.       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
  2806.     }
  2807. }
  2808.  
  2809. /************************* end of attributes *****************************/
  2810.  
  2811. /********************* utility routines for DIEs *************************/
  2812.  
  2813. /* Output an AT_name attribute and an AT_src_coords attribute for the
  2814.    given decl, but only if it actually has a name.  */
  2815.  
  2816. static void
  2817. name_and_src_coords_attributes (decl)
  2818.     register tree decl;
  2819. {
  2820.   register tree decl_name = DECL_NAME (decl);
  2821.  
  2822.   if (decl_name && IDENTIFIER_POINTER (decl_name))
  2823.     {
  2824.       name_attribute (IDENTIFIER_POINTER (decl_name));
  2825. #ifdef DWARF_DECL_COORDINATES
  2826.       {
  2827.     register unsigned file_index;
  2828.  
  2829.     /* This is annoying, but we have to pop out of the .debug section
  2830.        for a moment while we call `lookup_filename' because calling it
  2831.        may cause a temporary switch into the .debug_sfnames section and
  2832.        most svr4 assemblers are not smart enough be be able to nest
  2833.        section switches to any depth greater than one.  Note that we
  2834.        also can't skirt this issue by delaying all output to the
  2835.        .debug_sfnames section unit the end of compilation because that
  2836.        would cause us to have inter-section forward references and
  2837.        Fred Fish sez that m68k/svr4 assemblers botch those.  */
  2838.  
  2839.     ASM_OUTPUT_POP_SECTION (asm_out_file);
  2840.     file_index = lookup_filename (DECL_SOURCE_FILE (decl));
  2841.     ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
  2842.  
  2843.         src_coords_attribute (file_index, DECL_SOURCE_LINE (decl));
  2844.       }
  2845. #endif /* defined(DWARF_DECL_COORDINATES) */
  2846.     }
  2847. }
  2848.  
  2849. /* Many forms of DIEs contain a "type description" part.  The following
  2850.    routine writes out these "type descriptor" parts.  */
  2851.  
  2852. static void
  2853. type_attribute (type, decl_const, decl_volatile)
  2854.      register tree type;
  2855.      register int decl_const;
  2856.      register int decl_volatile;
  2857. {
  2858.   register enum tree_code code = TREE_CODE (type);
  2859.   register int root_type_modified;
  2860.  
  2861.   if (TREE_CODE (type) == ERROR_MARK)
  2862.     return;
  2863.  
  2864.   /* Handle a special case.  For functions whose return type is void,
  2865.      we generate *no* type attribute.  (Note that no object may have
  2866.      type `void', so this only applies to function return types.  */
  2867.  
  2868.   if (TREE_CODE (type) == VOID_TYPE)
  2869.     return;
  2870.  
  2871.   root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE
  2872.             || decl_const || decl_volatile
  2873.             || TYPE_READONLY (type) || TYPE_VOLATILE (type));
  2874.  
  2875.   if (type_is_fundamental (root_type (type)))
  2876.     if (root_type_modified)
  2877.     mod_fund_type_attribute (type, decl_const, decl_volatile);
  2878.     else
  2879.     fund_type_attribute (fundamental_type_code (type));
  2880.   else
  2881.     if (root_type_modified)
  2882.     mod_u_d_type_attribute (type, decl_const, decl_volatile);
  2883.     else
  2884.     /* We have to get the type_main_variant here (and pass that to the
  2885.        `user_def_type_attribute' routine) because the ..._TYPE node we
  2886.        have might simply be a *copy* of some original type node (where
  2887.        the copy was created to help us keep track of typedef names)
  2888.        and that copy might have a different TYPE_UID from the original
  2889.        ..._TYPE node.  (Note that when `equate_type_number_to_die_number'
  2890.        is labeling a given type DIE for future reference, it always and
  2891.        only creates labels for DIEs representing *main variants*, and it
  2892.        never even knows about non-main-variants.)  */
  2893.     user_def_type_attribute (type_main_variant (type));
  2894. }
  2895.  
  2896. /* Given a tree pointer to a struct, class, union, or enum type node, return
  2897.    a pointer to the (string) tag name for the given type, or zero if the
  2898.    type was declared without a tag.  */
  2899.  
  2900. static char *
  2901. type_tag (type)
  2902.      register tree type;
  2903. {
  2904.   register char *name = 0;
  2905.  
  2906.   if (TYPE_NAME (type) != 0)
  2907.     {
  2908.       register tree t = 0;
  2909.  
  2910.       /* Find the IDENTIFIER_NODE for the type name.  */
  2911.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  2912.     t = TYPE_NAME (type);
  2913. #if 0
  2914.       /* The g++ front end makes the TYPE_NAME of *each* tagged type point
  2915.      to a TYPE_DECL node, regardless of whether or not a `typedef' was
  2916.      involved.  This is distinctly different from what the gcc front-end
  2917.      does.  It always makes the TYPE_NAME for each tagged type be either
  2918.      NULL (signifying an anonymous tagged type) or else a pointer to an
  2919.      IDENTIFIER_NODE.  Obviously, we would like to generate correct Dwarf
  2920.      for both C and C++, but given this inconsistency in the TREE
  2921.      representation of tagged types for C and C++ in the GNU front-ends,
  2922.      we cannot support both languages correctly unless we introduce some
  2923.      front-end specific code here, and rms objects to that, so we can
  2924.      only generate correct Dwarf for one of these two languages.  C is
  2925.      more important, so for now we'll do the right thing for C and let
  2926.      g++ go fish.  */
  2927.  
  2928.       else
  2929.     if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  2930.       t = DECL_NAME (TYPE_NAME (type));
  2931. #endif
  2932.       /* Now get the name as a string, or invent one.  */
  2933.       if (t != 0)
  2934.     name = IDENTIFIER_POINTER (t);
  2935.     }
  2936.  
  2937.   return (name == 0 || *name == '\0') ? 0 : name;
  2938. }
  2939.  
  2940. inline void
  2941. dienum_push ()
  2942. {
  2943.   /* Start by checking if the pending_sibling_stack needs to be expanded.
  2944.      If necessary, expand it.  */
  2945.  
  2946.   if (pending_siblings == pending_siblings_allocated)
  2947.     {
  2948.       pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT;
  2949.       pending_sibling_stack
  2950.     = (unsigned *) xrealloc (pending_sibling_stack,
  2951.                  pending_siblings_allocated * sizeof(unsigned));
  2952.     }
  2953.  
  2954.   pending_siblings++;
  2955.   NEXT_DIE_NUM = next_unused_dienum++;
  2956. }
  2957.  
  2958. /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
  2959.    NEXT_DIE_NUM.  */
  2960.  
  2961. inline void
  2962. dienum_pop ()
  2963. {
  2964.   pending_siblings--;
  2965. }
  2966.  
  2967. inline tree
  2968. member_declared_type (member)
  2969.      register tree member;
  2970. {
  2971.   return (DECL_BIT_FIELD_TYPE (member))
  2972.        ? DECL_BIT_FIELD_TYPE (member)
  2973.        : TREE_TYPE (member);
  2974. }
  2975.  
  2976. /* Get the function's label, as described by its RTL.
  2977.    This may be different from the DECL_NAME name used
  2978.    in the source file.  */
  2979.  
  2980. static char *
  2981. function_start_label (decl)
  2982.     register tree decl;
  2983. {
  2984.   rtx x;
  2985.   char *fnname;
  2986.  
  2987.   x = DECL_RTL (decl);
  2988.   if (GET_CODE (x) != MEM)
  2989.     abort ();
  2990.   x = XEXP (x, 0);
  2991.   if (GET_CODE (x) != SYMBOL_REF)
  2992.            abort ();
  2993.   fnname = XSTR (x, 0);
  2994.   return fnname;
  2995. }
  2996.  
  2997.  
  2998. /******************************* DIEs ************************************/
  2999.  
  3000. /* Output routines for individual types of DIEs.  */
  3001.  
  3002. /* Note that every type of DIE (except a null DIE) gets a sibling.  */
  3003.  
  3004. static void
  3005. output_array_type_die (arg)
  3006.      register void *arg;
  3007. {
  3008.   register tree type = arg;
  3009.  
  3010.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
  3011.   sibling_attribute ();
  3012.   equate_type_number_to_die_number (type);
  3013.   member_attribute (TYPE_CONTEXT (type));
  3014.  
  3015.   /* I believe that we can default the array ordering.  SDB will probably
  3016.      do the right things even if AT_ordering is not present.  It's not
  3017.      even an issue until we start to get into multidimensional arrays
  3018.      anyway.  If SDB is ever caught doing the Wrong Thing for multi-
  3019.      dimensional arrays, then we'll have to put the AT_ordering attribute
  3020.      back in.  (But if and when we find out that we need to put these in,
  3021.      we will only do so for multidimensional arrays.  After all, we don't
  3022.      want to waste space in the .debug section now do we?)  */
  3023.  
  3024. #ifdef USE_ORDERING_ATTRIBUTE
  3025.   ordering_attribute (ORD_row_major);
  3026. #endif /* defined(USE_ORDERING_ATTRIBUTE) */
  3027.  
  3028.   subscript_data_attribute (type);
  3029. }
  3030.  
  3031. static void
  3032. output_set_type_die (arg)
  3033.      register void *arg;
  3034. {
  3035.   register tree type = arg;
  3036.  
  3037.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type);
  3038.   sibling_attribute ();
  3039.   equate_type_number_to_die_number (type);
  3040.   member_attribute (TYPE_CONTEXT (type));
  3041.   type_attribute (TREE_TYPE (type), 0, 0);
  3042. }
  3043.  
  3044. #if 0
  3045. /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
  3046. static void
  3047. output_entry_point_die (arg)
  3048.      register void *arg;
  3049. {
  3050.   register tree decl = arg;
  3051.   register tree origin = decl_ultimate_origin (decl);
  3052.  
  3053.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
  3054.   sibling_attribute ();
  3055.   dienum_push ();
  3056.   if (origin != NULL)
  3057.     abstract_origin_attribute (origin);
  3058.   else
  3059.     {
  3060.       name_and_src_coords_attributes (decl);
  3061.       member_attribute (DECL_CONTEXT (decl));
  3062.       type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0);
  3063.     }
  3064.   if (DECL_ABSTRACT (decl))
  3065.     equate_decl_number_to_die_number (decl);
  3066.   else
  3067.     low_pc_attribute (function_start_label (decl));
  3068. }
  3069. #endif
  3070.  
  3071. /* Output a DIE to represent an inlined instance of an enumeration type.  */
  3072.  
  3073. static void
  3074. output_inlined_enumeration_type_die (arg)
  3075.      register void *arg;
  3076. {
  3077.   register tree type = arg;
  3078.  
  3079.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
  3080.   sibling_attribute ();
  3081.   assert (TREE_ASM_WRITTEN (type));
  3082.   abstract_origin_attribute (type);
  3083. }
  3084.  
  3085. /* Output a DIE to represent an inlined instance of a structure type.  */
  3086.  
  3087. static void
  3088. output_inlined_structure_type_die (arg)
  3089.      register void *arg;
  3090. {
  3091.   register tree type = arg;
  3092.  
  3093.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
  3094.   sibling_attribute ();
  3095.   assert (TREE_ASM_WRITTEN (type));
  3096.   abstract_origin_attribute (type);
  3097. }
  3098.  
  3099. /* Output a DIE to represent an inlined instance of a union type.  */
  3100.  
  3101. static void
  3102. output_inlined_union_type_die (arg)
  3103.      register void *arg;
  3104. {
  3105.   register tree type = arg;
  3106.  
  3107.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
  3108.   sibling_attribute ();
  3109.   assert (TREE_ASM_WRITTEN (type));
  3110.   abstract_origin_attribute (type);
  3111. }
  3112.  
  3113. /* Output a DIE to represent an enumeration type.  Note that these DIEs
  3114.    include all of the information about the enumeration values also.
  3115.    This information is encoded into the element_list attribute.     */
  3116.  
  3117. static void
  3118. output_enumeration_type_die (arg)
  3119.      register void *arg;
  3120. {
  3121.   register tree type = arg;
  3122.  
  3123.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
  3124.   sibling_attribute ();
  3125.   equate_type_number_to_die_number (type);
  3126.   name_attribute (type_tag (type));
  3127.   member_attribute (TYPE_CONTEXT (type));
  3128.  
  3129.   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
  3130.      given enum type is incomplete, do not generate the AT_byte_size
  3131.      attribute or the AT_element_list attribute.  */
  3132.  
  3133.   if (TYPE_SIZE (type))
  3134.     {
  3135.       byte_size_attribute (type);
  3136.       element_list_attribute (TYPE_FIELDS (type));
  3137.     }
  3138. }
  3139.  
  3140. /* Output a DIE to represent either a real live formal parameter decl or
  3141.    to represent just the type of some formal parameter position in some
  3142.    function type.
  3143.  
  3144.    Note that this routine is a bit unusual because its argument may be
  3145.    a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
  3146.    represents an inlining of some PARM_DECL) or else some sort of a
  3147.    ..._TYPE node.  If it's the former then this function is being called
  3148.    to output a DIE to represent a formal parameter object (or some inlining
  3149.    thereof).  If it's the latter, then this function is only being called
  3150.    to output a TAG_formal_parameter DIE to stand as a placeholder for some
  3151.    formal argument type of some subprogram type.  */
  3152.  
  3153. static void
  3154. output_formal_parameter_die (arg)
  3155.      register void *arg;
  3156. {
  3157.   register tree node = arg;
  3158.  
  3159.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
  3160.   sibling_attribute ();
  3161.  
  3162.   switch (TREE_CODE_CLASS (TREE_CODE (node)))
  3163.     {
  3164.     case 'd':    /* We were called with some kind of a ..._DECL node.  */
  3165.       {
  3166.     register tree origin = decl_ultimate_origin (node);
  3167.  
  3168.     if (origin != NULL)
  3169.       abstract_origin_attribute (origin);
  3170.     else
  3171.       {
  3172.         name_and_src_coords_attributes (node);
  3173.         type_attribute (TREE_TYPE (node),
  3174.                 TREE_READONLY (node), TREE_THIS_VOLATILE (node));
  3175.       }
  3176.     if (DECL_ABSTRACT (node))
  3177.       equate_decl_number_to_die_number (node);
  3178.     else
  3179.       location_or_const_value_attribute (node);
  3180.       }
  3181.       break;
  3182.  
  3183.     case 't':    /* We were called with some kind of a ..._TYPE node.  */
  3184.       type_attribute (node, 0, 0);
  3185.       break;
  3186.  
  3187.     default:
  3188.       abort ();    /* Should never happen.  */
  3189.     }
  3190. }
  3191.  
  3192. /* Output a DIE to represent a declared function (either file-scope
  3193.    or block-local) which has "external linkage" (according to ANSI-C).  */
  3194.  
  3195. static void
  3196. output_global_subroutine_die (arg)
  3197.      register void *arg;
  3198. {
  3199.   register tree decl = arg;
  3200.   register tree origin = decl_ultimate_origin (decl);
  3201.  
  3202.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
  3203.   sibling_attribute ();
  3204.   dienum_push ();
  3205.   if (origin != NULL)
  3206.     abstract_origin_attribute (origin);
  3207.   else
  3208.     {
  3209.       register tree type = TREE_TYPE (decl);
  3210.  
  3211.       name_and_src_coords_attributes (decl);
  3212.       inline_attribute (decl);
  3213.       prototyped_attribute (type);
  3214.       member_attribute (DECL_CONTEXT (decl));
  3215.       type_attribute (TREE_TYPE (type), 0, 0);
  3216.       pure_or_virtual_attribute (decl);
  3217.     }
  3218.   if (DECL_ABSTRACT (decl))
  3219.     equate_decl_number_to_die_number (decl);
  3220.   else
  3221.     {
  3222.       if (! DECL_EXTERNAL (decl))
  3223.     {
  3224.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3225.  
  3226.       low_pc_attribute (function_start_label (decl));
  3227.       sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
  3228.       high_pc_attribute (label);
  3229.       sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
  3230.       body_begin_attribute (label);
  3231.       sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
  3232.       body_end_attribute (label);
  3233.     }
  3234.     }
  3235. }
  3236.  
  3237. /* Output a DIE to represent a declared data object (either file-scope
  3238.    or block-local) which has "external linkage" (according to ANSI-C).  */
  3239.  
  3240. static void
  3241. output_global_variable_die (arg)
  3242.      register void *arg;
  3243. {
  3244.   register tree decl = arg;
  3245.   register tree origin = decl_ultimate_origin (decl);
  3246.  
  3247.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
  3248.   sibling_attribute ();
  3249.   if (origin != NULL)
  3250.     abstract_origin_attribute (origin);
  3251.   else
  3252.     {
  3253.       name_and_src_coords_attributes (decl);
  3254.       member_attribute (DECL_CONTEXT (decl));
  3255.       type_attribute (TREE_TYPE (decl),
  3256.               TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
  3257.     }
  3258.   if (DECL_ABSTRACT (decl))
  3259.     equate_decl_number_to_die_number (decl);
  3260.   else
  3261.     {
  3262.       if (!DECL_EXTERNAL (decl))
  3263.     location_or_const_value_attribute (decl);
  3264.     }
  3265. }
  3266.  
  3267. static void
  3268. output_label_die (arg)
  3269.      register void *arg;
  3270. {
  3271.   register tree decl = arg;
  3272.   register tree origin = decl_ultimate_origin (decl);
  3273.  
  3274.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
  3275.   sibling_attribute ();
  3276.   if (origin != NULL)
  3277.     abstract_origin_attribute (origin);
  3278.   else
  3279.     name_and_src_coords_attributes (decl);
  3280.   if (DECL_ABSTRACT (decl))
  3281.     equate_decl_number_to_die_number (decl);
  3282.   else
  3283.     {
  3284.       register rtx insn = DECL_RTL (decl);
  3285.  
  3286.       if (GET_CODE (insn) == CODE_LABEL)
  3287.     {
  3288.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3289.  
  3290.       /* When optimization is enabled (via -O) some parts of the compiler
  3291.          (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
  3292.          represent source-level labels which were explicitly declared by
  3293.          the user.  This really shouldn't be happening though, so catch
  3294.          it if it ever does happen.  */
  3295.  
  3296.       if (INSN_DELETED_P (insn))
  3297.         abort ();    /* Should never happen.  */
  3298.  
  3299.       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
  3300.                           (unsigned) INSN_UID (insn));
  3301.       low_pc_attribute (label);
  3302.     }
  3303.     }
  3304. }
  3305.  
  3306. static void
  3307. output_lexical_block_die (arg)
  3308.      register void *arg;
  3309. {
  3310.   register tree stmt = arg;
  3311.  
  3312.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
  3313.   sibling_attribute ();
  3314.   dienum_push ();
  3315.   if (! BLOCK_ABSTRACT (stmt))
  3316.     {
  3317.       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3318.       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3319.  
  3320.       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
  3321.       low_pc_attribute (begin_label);
  3322.       sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
  3323.       high_pc_attribute (end_label);
  3324.     }
  3325. }
  3326.  
  3327. static void
  3328. output_inlined_subroutine_die (arg)
  3329.      register void *arg;
  3330. {
  3331.   register tree stmt = arg;
  3332.  
  3333.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine);
  3334.   sibling_attribute ();
  3335.   dienum_push ();
  3336.   abstract_origin_attribute (block_ultimate_origin (stmt));
  3337.   if (! BLOCK_ABSTRACT (stmt))
  3338.     {
  3339.       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3340.       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3341.  
  3342.       sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
  3343.       low_pc_attribute (begin_label);
  3344.       sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
  3345.       high_pc_attribute (end_label);
  3346.     }
  3347. }
  3348.  
  3349. /* Output a DIE to represent a declared data object (either file-scope
  3350.    or block-local) which has "internal linkage" (according to ANSI-C).  */
  3351.  
  3352. static void
  3353. output_local_variable_die (arg)
  3354.      register void *arg;
  3355. {
  3356.   register tree decl = arg;
  3357.   register tree origin = decl_ultimate_origin (decl);
  3358.  
  3359.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
  3360.   sibling_attribute ();
  3361.   if (origin != NULL)
  3362.     abstract_origin_attribute (origin);
  3363.   else
  3364.     {
  3365.       name_and_src_coords_attributes (decl);
  3366.       member_attribute (DECL_CONTEXT (decl));
  3367.       type_attribute (TREE_TYPE (decl),
  3368.               TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
  3369.     }
  3370.   if (DECL_ABSTRACT (decl))
  3371.     equate_decl_number_to_die_number (decl);
  3372.   else
  3373.     location_or_const_value_attribute (decl);
  3374. }
  3375.  
  3376. static void
  3377. output_member_die (arg)
  3378.      register void *arg;
  3379. {
  3380.   register tree decl = arg;
  3381.  
  3382.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
  3383.   sibling_attribute ();
  3384.   name_and_src_coords_attributes (decl);
  3385.   member_attribute (DECL_CONTEXT (decl));
  3386.   type_attribute (member_declared_type (decl),
  3387.           TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
  3388.   if (DECL_BIT_FIELD_TYPE (decl))    /* If this is a bit field... */
  3389.     {
  3390.       byte_size_attribute (decl);
  3391.       bit_size_attribute (decl);
  3392.       bit_offset_attribute (decl);
  3393.     }
  3394.   data_member_location_attribute (decl);
  3395. }
  3396.  
  3397. #if 0
  3398. /* Don't generate either pointer_type DIEs or reference_type DIEs.  Use
  3399.    modified types instead.
  3400.  
  3401.    We keep this code here just in case these types of DIEs may be needed
  3402.    to represent certain things in other languages (e.g. Pascal) someday.
  3403. */
  3404.  
  3405. static void
  3406. output_pointer_type_die (arg)
  3407.      register void *arg;
  3408. {
  3409.   register tree type = arg;
  3410.  
  3411.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
  3412.   sibling_attribute ();
  3413.   equate_type_number_to_die_number (type);
  3414.   member_attribute (TYPE_CONTEXT (type));
  3415.   type_attribute (TREE_TYPE (type), 0, 0);
  3416. }
  3417.  
  3418. static void
  3419. output_reference_type_die (arg)
  3420.      register void *arg;
  3421. {
  3422.   register tree type = arg;
  3423.  
  3424.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
  3425.   sibling_attribute ();
  3426.   equate_type_number_to_die_number (type);
  3427.   member_attribute (TYPE_CONTEXT (type));
  3428.   type_attribute (TREE_TYPE (type), 0, 0);
  3429. }
  3430. #endif
  3431.  
  3432. static void
  3433. output_ptr_to_mbr_type_die (arg)
  3434.      register void *arg;
  3435. {
  3436.   register tree type = arg;
  3437.  
  3438.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type);
  3439.   sibling_attribute ();
  3440.   equate_type_number_to_die_number (type);
  3441.   member_attribute (TYPE_CONTEXT (type));
  3442.   containing_type_attribute (TYPE_OFFSET_BASETYPE (type));
  3443.   type_attribute (TREE_TYPE (type), 0, 0);
  3444. }
  3445.  
  3446. static void
  3447. output_compile_unit_die (arg)
  3448.      register void *arg;
  3449. {
  3450.   register char *main_input_filename = arg;
  3451.  
  3452.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit);
  3453.   sibling_attribute ();
  3454.   dienum_push ();
  3455.   name_attribute (main_input_filename);
  3456.  
  3457.   {
  3458.     char producer[250];
  3459.  
  3460.     sprintf (producer, "%s %s", language_string, version_string);
  3461.     producer_attribute (producer);
  3462.   }
  3463.  
  3464.   if (strcmp (language_string, "GNU C++") == 0)
  3465.     language_attribute (LANG_C_PLUS_PLUS);
  3466.   else if (strcmp (language_string, "GNU Ada") == 0)
  3467.     language_attribute (LANG_ADA83);
  3468.   else if (flag_traditional)
  3469.     language_attribute (LANG_C);
  3470.   else
  3471.     language_attribute (LANG_C89);
  3472.   low_pc_attribute (TEXT_BEGIN_LABEL);
  3473.   high_pc_attribute (TEXT_END_LABEL);
  3474.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  3475.     stmt_list_attribute (LINE_BEGIN_LABEL);
  3476.   last_filename = xstrdup (main_input_filename);
  3477.  
  3478.   {
  3479.     char *wd = getpwd ();
  3480.     if (wd)
  3481.       comp_dir_attribute (wd);
  3482.   }
  3483.  
  3484.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  3485.     {
  3486.       sf_names_attribute (SFNAMES_BEGIN_LABEL);
  3487.       src_info_attribute (SRCINFO_BEGIN_LABEL);
  3488.       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  3489.         mac_info_attribute (MACINFO_BEGIN_LABEL);
  3490.     }
  3491. }
  3492.  
  3493. static void
  3494. output_string_type_die (arg)
  3495.      register void *arg;
  3496. {
  3497.   register tree type = arg;
  3498.  
  3499.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
  3500.   sibling_attribute ();
  3501.   member_attribute (TYPE_CONTEXT (type));
  3502.  
  3503.   /* Fudge the string length attribute for now.  */
  3504.  
  3505.   string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
  3506. }
  3507.  
  3508. static void
  3509. output_structure_type_die (arg)
  3510.      register void *arg;
  3511. {
  3512.   register tree type = arg;
  3513.  
  3514.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
  3515.   sibling_attribute ();
  3516.   equate_type_number_to_die_number (type);
  3517.   name_attribute (type_tag (type));
  3518.   member_attribute (TYPE_CONTEXT (type));
  3519.  
  3520.   /* If this type has been completed, then give it a byte_size attribute
  3521.      and prepare to give a list of members.  Otherwise, don't do either of
  3522.      these things.  In the latter case, we will not be generating a list
  3523.      of members (since we don't have any idea what they might be for an
  3524.      incomplete type).    */
  3525.  
  3526.   if (TYPE_SIZE (type))
  3527.     {
  3528.       dienum_push ();
  3529.       byte_size_attribute (type);
  3530.     }
  3531. }
  3532.  
  3533. /* Output a DIE to represent a declared function (either file-scope
  3534.    or block-local) which has "internal linkage" (according to ANSI-C).  */
  3535.  
  3536. static void
  3537. output_local_subroutine_die (arg)
  3538.      register void *arg;
  3539. {
  3540.   register tree decl = arg;
  3541.   register tree origin = decl_ultimate_origin (decl);
  3542.  
  3543.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
  3544.   sibling_attribute ();
  3545.   dienum_push ();
  3546.   if (origin != NULL)
  3547.     abstract_origin_attribute (origin);
  3548.   else
  3549.     {
  3550.       register tree type = TREE_TYPE (decl);
  3551.  
  3552.       name_and_src_coords_attributes (decl);
  3553.       inline_attribute (decl);
  3554.       prototyped_attribute (type);
  3555.       member_attribute (DECL_CONTEXT (decl));
  3556.       type_attribute (TREE_TYPE (type), 0, 0);
  3557.       pure_or_virtual_attribute (decl);
  3558.     }
  3559.   if (DECL_ABSTRACT (decl))
  3560.     equate_decl_number_to_die_number (decl);
  3561.   else
  3562.     {
  3563.       /* Avoid getting screwed up in cases where a function was declared
  3564.      static but where no definition was ever given for it.  */
  3565.  
  3566.       if (TREE_ASM_WRITTEN (decl))
  3567.     {
  3568.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3569.       low_pc_attribute (function_start_label (decl));
  3570.       sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
  3571.       high_pc_attribute (label);
  3572.       sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
  3573.       body_begin_attribute (label);
  3574.       sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
  3575.       body_end_attribute (label);
  3576.     }
  3577.     }
  3578. }
  3579.  
  3580. static void
  3581. output_subroutine_type_die (arg)
  3582.      register void *arg;
  3583. {
  3584.   register tree type = arg;
  3585.   register tree return_type = TREE_TYPE (type);
  3586.  
  3587.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
  3588.   sibling_attribute ();
  3589.   dienum_push ();
  3590.   equate_type_number_to_die_number (type);
  3591.   prototyped_attribute (type);
  3592.   member_attribute (TYPE_CONTEXT (type));
  3593.   type_attribute (return_type, 0, 0);
  3594. }
  3595.  
  3596. static void
  3597. output_typedef_die (arg)
  3598.      register void *arg;
  3599. {
  3600.   register tree decl = arg;
  3601.   register tree origin = decl_ultimate_origin (decl);
  3602.  
  3603.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
  3604.   sibling_attribute ();
  3605.   if (origin != NULL)
  3606.     abstract_origin_attribute (origin);
  3607.   else
  3608.     {
  3609.       name_and_src_coords_attributes (decl);
  3610.       member_attribute (DECL_CONTEXT (decl));
  3611.       type_attribute (TREE_TYPE (decl),
  3612.               TREE_READONLY (decl), TREE_THIS_VOLATILE (decl));
  3613.     }
  3614.   if (DECL_ABSTRACT (decl))
  3615.     equate_decl_number_to_die_number (decl);
  3616. }
  3617.  
  3618. static void
  3619. output_union_type_die (arg)
  3620.      register void *arg;
  3621. {
  3622.   register tree type = arg;
  3623.  
  3624.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
  3625.   sibling_attribute ();
  3626.   equate_type_number_to_die_number (type);
  3627.   name_attribute (type_tag (type));
  3628.   member_attribute (TYPE_CONTEXT (type));
  3629.  
  3630.   /* If this type has been completed, then give it a byte_size attribute
  3631.      and prepare to give a list of members.  Otherwise, don't do either of
  3632.      these things.  In the latter case, we will not be generating a list
  3633.      of members (since we don't have any idea what they might be for an
  3634.      incomplete type).    */
  3635.  
  3636.   if (TYPE_SIZE (type))
  3637.     {
  3638.       dienum_push ();
  3639.       byte_size_attribute (type);
  3640.     }
  3641. }
  3642.  
  3643. /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
  3644.    at the end of an (ANSI prototyped) formal parameters list.  */
  3645.  
  3646. static void
  3647. output_unspecified_parameters_die (arg)
  3648.      register void *arg;
  3649. {
  3650.   register tree decl_or_type = arg;
  3651.  
  3652.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
  3653.   sibling_attribute ();
  3654.  
  3655.   /* This kludge is here only for the sake of being compatible with what
  3656.      the USL CI5 C compiler does.  The specification of Dwarf Version 1
  3657.      doesn't say that TAG_unspecified_parameters DIEs should contain any
  3658.      attributes other than the AT_sibling attribute, but they are certainly
  3659.      allowed to contain additional attributes, and the CI5 compiler
  3660.      generates AT_name, AT_fund_type, and AT_location attributes within
  3661.      TAG_unspecified_parameters DIEs which appear in the child lists for
  3662.      DIEs representing function definitions, so we do likewise here.  */
  3663.  
  3664.   if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type))
  3665.     {
  3666.       name_attribute ("...");
  3667.       fund_type_attribute (FT_pointer);
  3668.       /* location_attribute (?); */
  3669.     }
  3670. }
  3671.  
  3672. static void
  3673. output_padded_null_die (arg)
  3674.      register void *arg;
  3675. {
  3676.   ASM_OUTPUT_ALIGN (asm_out_file, 2);    /* 2**2 == 4 */
  3677. }
  3678.  
  3679. /*************************** end of DIEs *********************************/
  3680.  
  3681. /* Generate some type of DIE.  This routine generates the generic outer
  3682.    wrapper stuff which goes around all types of DIE's (regardless of their
  3683.    TAGs.  All forms of DIEs start with a DIE-specific label, followed by a
  3684.    DIE-length word, followed by the guts of the DIE itself.  After the guts
  3685.    of the DIE, there must always be a terminator label for the DIE.  */
  3686.  
  3687. static void
  3688. output_die (die_specific_output_function, param)
  3689.      register void (*die_specific_output_function)();
  3690.      register void *param;
  3691. {
  3692.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3693.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3694.  
  3695.   current_dienum = NEXT_DIE_NUM;
  3696.   NEXT_DIE_NUM = next_unused_dienum;
  3697.  
  3698.   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  3699.   sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
  3700.  
  3701.   /* Write a label which will act as the name for the start of this DIE.  */
  3702.  
  3703.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  3704.  
  3705.   /* Write the DIE-length word.     */
  3706.  
  3707.   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label);
  3708.  
  3709.   /* Fill in the guts of the DIE.  */
  3710.  
  3711.   next_unused_dienum++;
  3712.   die_specific_output_function (param);
  3713.  
  3714.   /* Write a label which will act as the name for the end of this DIE.    */
  3715.  
  3716.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  3717. }
  3718.  
  3719. static void
  3720. end_sibling_chain ()
  3721. {
  3722.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3723.  
  3724.   current_dienum = NEXT_DIE_NUM;
  3725.   NEXT_DIE_NUM = next_unused_dienum;
  3726.  
  3727.   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  3728.  
  3729.   /* Write a label which will act as the name for the start of this DIE.  */
  3730.  
  3731.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  3732.  
  3733.   /* Write the DIE-length word.     */
  3734.  
  3735.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
  3736.  
  3737.   dienum_pop ();
  3738. }
  3739.  
  3740. /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a
  3741.    TAG_unspecified_parameters DIE) to represent the types of the formal
  3742.    parameters as specified in some function type specification (except
  3743.    for those which appear as part of a function *definition*).
  3744.  
  3745.    Note that we must be careful here to output all of the parameter DIEs
  3746.    *before* we output any DIEs needed to represent the types of the formal
  3747.    parameters.  This keeps svr4 SDB happy because it (incorrectly) thinks
  3748.    that the first non-parameter DIE it sees ends the formal parameter list.
  3749. */
  3750.  
  3751. static void
  3752. output_formal_types (function_or_method_type)
  3753.      register tree function_or_method_type;
  3754. {
  3755.   register tree link;
  3756.   register tree formal_type = NULL;
  3757.   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
  3758.  
  3759.   /* In the case where we are generating a formal types list for a C++
  3760.      non-static member function type, skip over the first thing on the
  3761.      TYPE_ARG_TYPES list because it only represents the type of the
  3762.      hidden `this pointer'.  The debugger should be able to figure
  3763.      out (without being explicitly told) that this non-static member
  3764.      function type takes a `this pointer' and should be able to figure
  3765.      what the type of that hidden parameter is from the AT_member
  3766.      attribute of the parent TAG_subroutine_type DIE.  */
  3767.  
  3768.   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
  3769.     first_parm_type = TREE_CHAIN (first_parm_type);
  3770.  
  3771.   /* Make our first pass over the list of formal parameter types and output
  3772.      a TAG_formal_parameter DIE for each one.  */
  3773.  
  3774.   for (link = first_parm_type; link; link = TREE_CHAIN (link))
  3775.     {
  3776.       formal_type = TREE_VALUE (link);
  3777.       if (formal_type == void_type_node)
  3778.     break;
  3779.  
  3780.       /* Output a (nameless) DIE to represent the formal parameter itself.  */
  3781.  
  3782.       output_die (output_formal_parameter_die, formal_type);
  3783.     }
  3784.  
  3785.   /* If this function type has an ellipsis, add a TAG_unspecified_parameters
  3786.      DIE to the end of the parameter list.  */
  3787.  
  3788.   if (formal_type != void_type_node)
  3789.     output_die (output_unspecified_parameters_die, function_or_method_type);
  3790.  
  3791.   /* Make our second (and final) pass over the list of formal parameter types
  3792.      and output DIEs to represent those types (as necessary).  */
  3793.  
  3794.   for (link = TYPE_ARG_TYPES (function_or_method_type);
  3795.        link;
  3796.        link = TREE_CHAIN (link))
  3797.     {
  3798.       formal_type = TREE_VALUE (link);
  3799.       if (formal_type == void_type_node)
  3800.     break;
  3801.  
  3802.       output_type (formal_type, function_or_method_type);
  3803.     }
  3804. }
  3805.  
  3806. /* Remember a type in the pending_types_list.  */
  3807.  
  3808. static void
  3809. pend_type (type)
  3810.      register tree type;
  3811. {
  3812.   if (pending_types == pending_types_allocated)
  3813.     {
  3814.       pending_types_allocated += PENDING_TYPES_INCREMENT;
  3815.       pending_types_list
  3816.     = (tree *) xrealloc (pending_types_list,
  3817.                  sizeof (tree) * pending_types_allocated);
  3818.     }
  3819.   pending_types_list[pending_types++] = type;
  3820.  
  3821.   /* Mark the pending type as having been output already (even though
  3822.      it hasn't been).  This prevents the type from being added to the
  3823.      pending_types_list more than once.  */
  3824.  
  3825.   TREE_ASM_WRITTEN (type) = 1;
  3826. }
  3827.  
  3828. /* Return non-zero if it is legitimate to output DIEs to represent a
  3829.    given type while we are generating the list of child DIEs for some
  3830.    DIE (e.g. a function or lexical block DIE) associated with a given scope.
  3831.  
  3832.    See the comments within the function for a description of when it is
  3833.    considered legitimate to output DIEs for various kinds of types.
  3834.  
  3835.    Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope)
  3836.    or it may point to a BLOCK node (for types local to a block), or to a
  3837.    FUNCTION_DECL node (for types local to the heading of some function
  3838.    definition), or to a FUNCTION_TYPE node (for types local to the
  3839.    prototyped parameter list of a function type specification), or to a
  3840.    RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node
  3841.    (in the case of C++ nested types).
  3842.  
  3843.    The `scope' parameter should likewise be NULL or should point to a
  3844.    BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE
  3845.    node, a UNION_TYPE node, or a QUAL_UNION_TYPE node.
  3846.  
  3847.    This function is used only for deciding when to "pend" and when to
  3848.    "un-pend" types to/from the pending_types_list.
  3849.  
  3850.    Note that we sometimes make use of this "type pending" feature in a
  3851.    rather twisted way to temporarily delay the production of DIEs for the
  3852.    types of formal parameters.  (We do this just to make svr4 SDB happy.)
  3853.    It order to delay the production of DIEs representing types of formal
  3854.    parameters, callers of this function supply `fake_containing_scope' as
  3855.    the `scope' parameter to this function.  Given that fake_containing_scope
  3856.    is a tagged type which is *not* the containing scope for *any* other type,
  3857.    the desired effect is achieved, i.e. output of DIEs representing types
  3858.    is temporarily suspended, and any type DIEs which would have otherwise
  3859.    been output are instead placed onto the pending_types_list.  Later on,
  3860.    we force these (temporarily pended) types to be output simply by calling
  3861.    `output_pending_types_for_scope' with an actual argument equal to the
  3862.    true scope of the types we temporarily pended.
  3863. */
  3864.  
  3865. inline int
  3866. type_ok_for_scope (type, scope)
  3867.     register tree type;
  3868.     register tree scope;
  3869. {
  3870.   /* Tagged types (i.e. struct, union, and enum types) must always be
  3871.      output only in the scopes where they actually belong (or else the
  3872.      scoping of their own tag names and the scoping of their member
  3873.      names will be incorrect).  Non-tagged-types on the other hand can
  3874.      generally be output anywhere, except that svr4 SDB really doesn't
  3875.      want to see them nested within struct or union types, so here we
  3876.      say it is always OK to immediately output any such a (non-tagged)
  3877.      type, so long as we are not within such a context.  Note that the
  3878.      only kinds of non-tagged types which we will be dealing with here
  3879.      (for C and C++ anyway) will be array types and function types.  */
  3880.  
  3881.   return is_tagged_type (type)
  3882.      ? (TYPE_CONTEXT (type) == scope)
  3883.      : (scope == NULL_TREE || ! is_tagged_type (scope));
  3884. }
  3885.  
  3886. /* Output any pending types (from the pending_types list) which we can output
  3887.    now (taking into account the scope that we are working on now).
  3888.  
  3889.    For each type output, remove the given type from the pending_types_list
  3890.    *before* we try to output it.
  3891.  
  3892.    Note that we have to process the list in beginning-to-end order,
  3893.    because the call made here to output_type may cause yet more types
  3894.    to be added to the end of the list, and we may have to output some
  3895.    of them too.
  3896. */
  3897.  
  3898. static void
  3899. output_pending_types_for_scope (containing_scope)
  3900.      register tree containing_scope;
  3901. {
  3902.   register unsigned i;
  3903.  
  3904.   for (i = 0; i < pending_types; )
  3905.     {
  3906.       register tree type = pending_types_list[i];
  3907.  
  3908.       if (type_ok_for_scope (type, containing_scope))
  3909.     {
  3910.       register tree *mover;
  3911.       register tree *limit;
  3912.  
  3913.       pending_types--;
  3914.       limit = &pending_types_list[pending_types];
  3915.       for (mover = &pending_types_list[i]; mover < limit; mover++)
  3916.         *mover = *(mover+1);
  3917.  
  3918.       /* Un-mark the type as having been output already (because it
  3919.          hasn't been, really).  Then call output_type to generate a
  3920.          Dwarf representation of it.  */
  3921.  
  3922.       TREE_ASM_WRITTEN (type) = 0;
  3923.       output_type (type, containing_scope);
  3924.  
  3925.       /* Don't increment the loop counter in this case because we
  3926.          have shifted all of the subsequent pending types down one
  3927.          element in the pending_types_list array.  */
  3928.     }
  3929.       else
  3930.     i++;
  3931.     }
  3932. }
  3933.  
  3934. static void
  3935. output_type (type, containing_scope)
  3936.      register tree type;
  3937.      register tree containing_scope;
  3938. {
  3939.   if (type == 0 || type == error_mark_node)
  3940.     return;
  3941.  
  3942.   /* We are going to output a DIE to represent the unqualified version of
  3943.      of this type (i.e. without any const or volatile qualifiers) so get
  3944.      the main variant (i.e. the unqualified version) of this type now.  */
  3945.  
  3946.   type = type_main_variant (type);
  3947.  
  3948.   if (TREE_ASM_WRITTEN (type))
  3949.     return;
  3950.  
  3951.   /* Don't generate any DIEs for this type now unless it is OK to do so
  3952.      (based upon what `type_ok_for_scope' tells us).  */
  3953.  
  3954.   if (! type_ok_for_scope (type, containing_scope))
  3955.     {
  3956.       pend_type (type);
  3957.       return;
  3958.     }
  3959.  
  3960.   switch (TREE_CODE (type))
  3961.     {
  3962.       case ERROR_MARK:
  3963.     break;
  3964.  
  3965.       case POINTER_TYPE:
  3966.       case REFERENCE_TYPE:
  3967.     /* For these types, all that is required is that we output a DIE
  3968.        (or a set of DIEs) to represent the "basis" type.  */
  3969.     output_type (TREE_TYPE (type), containing_scope);
  3970.     break;
  3971.  
  3972.       case OFFSET_TYPE:
  3973.     /* This code is used for C++ pointer-to-data-member types.  */
  3974.     /* Output a description of the relevant class type.  */
  3975.     output_type (TYPE_OFFSET_BASETYPE (type), containing_scope);
  3976.     /* Output a description of the type of the object pointed to.  */
  3977.     output_type (TREE_TYPE (type), containing_scope);
  3978.     /* Now output a DIE to represent this pointer-to-data-member type
  3979.        itself.  */
  3980.     output_die (output_ptr_to_mbr_type_die, type);
  3981.     break;
  3982.  
  3983.       case SET_TYPE:
  3984.     output_type (TYPE_DOMAIN (type), containing_scope);
  3985.     output_die (output_set_type_die, type);
  3986.     break;
  3987.  
  3988.       case FILE_TYPE:
  3989.     output_type (TREE_TYPE (type), containing_scope);
  3990.     abort ();    /* No way to represent these in Dwarf yet!  */
  3991.     break;
  3992.  
  3993.       case FUNCTION_TYPE:
  3994.     /* Force out return type (in case it wasn't forced out already).  */
  3995.     output_type (TREE_TYPE (type), containing_scope);
  3996.     output_die (output_subroutine_type_die, type);
  3997.     output_formal_types (type);
  3998.     end_sibling_chain ();
  3999.     break;
  4000.  
  4001.       case METHOD_TYPE:
  4002.     /* Force out return type (in case it wasn't forced out already).  */
  4003.     output_type (TREE_TYPE (type), containing_scope);
  4004.     output_die (output_subroutine_type_die, type);
  4005.     output_formal_types (type);
  4006.     end_sibling_chain ();
  4007.     break;
  4008.  
  4009.       case ARRAY_TYPE:    
  4010.     if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE)
  4011.       {
  4012.         output_type (TREE_TYPE (type), containing_scope);
  4013.         output_die (output_string_type_die, type);
  4014.       }
  4015.     else
  4016.       {
  4017.         register tree element_type;
  4018.  
  4019.         element_type = TREE_TYPE (type);
  4020.         while (TREE_CODE (element_type) == ARRAY_TYPE)
  4021.           element_type = TREE_TYPE (element_type);
  4022.  
  4023.         output_type (element_type, containing_scope);
  4024.         output_die (output_array_type_die, type);
  4025.       }
  4026.     break;
  4027.  
  4028.       case ENUMERAL_TYPE:
  4029.       case RECORD_TYPE:
  4030.       case UNION_TYPE:
  4031.       case QUAL_UNION_TYPE:
  4032.  
  4033.     /* For a non-file-scope tagged type, we can always go ahead and
  4034.        output a Dwarf description of this type right now, even if
  4035.        the type in question is still incomplete, because if this
  4036.        local type *was* ever completed anywhere within its scope,
  4037.        that complete definition would already have been attached to
  4038.        this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE
  4039.        node by the time we reach this point.  That's true because of the
  4040.        way the front-end does its processing of file-scope declarations (of
  4041.        functions and class types) within which other types might be
  4042.        nested.  The C and C++ front-ends always gobble up such "local
  4043.        scope" things en-mass before they try to output *any* debugging
  4044.        information for any of the stuff contained inside them and thus,
  4045.        we get the benefit here of what is (in effect) a pre-resolution
  4046.        of forward references to tagged types in local scopes.
  4047.  
  4048.        Note however that for file-scope tagged types we cannot assume
  4049.        that such pre-resolution of forward references has taken place.
  4050.        A given file-scope tagged type may appear to be incomplete when
  4051.        we reach this point, but it may yet be given a full definition
  4052.        (at file-scope) later on during compilation.  In order to avoid
  4053.        generating a premature (and possibly incorrect) set of Dwarf
  4054.        DIEs for such (as yet incomplete) file-scope tagged types, we
  4055.        generate nothing at all for as-yet incomplete file-scope tagged
  4056.        types here unless we are making our special "finalization" pass
  4057.        for file-scope things at the very end of compilation.  At that
  4058.        time, we will certainly know as much about each file-scope tagged
  4059.        type as we are ever going to know, so at that point in time, we
  4060.        can safely generate correct Dwarf descriptions for these file-
  4061.        scope tagged types.
  4062.     */
  4063.  
  4064.     if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing)
  4065.       return;    /* EARLY EXIT!  Avoid setting TREE_ASM_WRITTEN.  */
  4066.  
  4067.     /* Prevent infinite recursion in cases where the type of some
  4068.        member of this type is expressed in terms of this type itself.  */
  4069.  
  4070.     TREE_ASM_WRITTEN (type) = 1;
  4071.  
  4072.     /* Output a DIE to represent the tagged type itself.  */
  4073.  
  4074.     switch (TREE_CODE (type))
  4075.       {
  4076.       case ENUMERAL_TYPE:
  4077.         output_die (output_enumeration_type_die, type);
  4078.         return;  /* a special case -- nothing left to do so just return */
  4079.  
  4080.       case RECORD_TYPE:
  4081.         output_die (output_structure_type_die, type);
  4082.         break;
  4083.  
  4084.       case UNION_TYPE:
  4085.       case QUAL_UNION_TYPE:
  4086.         output_die (output_union_type_die, type);
  4087.         break;
  4088.  
  4089.       default:
  4090.         abort ();    /* Should never happen.  */
  4091.       }
  4092.  
  4093.     /* If this is not an incomplete type, output descriptions of
  4094.        each of its members.
  4095.  
  4096.        Note that as we output the DIEs necessary to represent the
  4097.        members of this record or union type, we will also be trying
  4098.        to output DIEs to represent the *types* of those members.
  4099.        However the `output_type' function (above) will specifically
  4100.        avoid generating type DIEs for member types *within* the list
  4101.        of member DIEs for this (containing) type execpt for those
  4102.        types (of members) which are explicitly marked as also being
  4103.        members of this (containing) type themselves.  The g++ front-
  4104.        end can force any given type to be treated as a member of some
  4105.        other (containing) type by setting the TYPE_CONTEXT of the
  4106.        given (member) type to point to the TREE node representing the
  4107.        appropriate (containing) type.
  4108.     */
  4109.  
  4110.     if (TYPE_SIZE (type))
  4111.       {
  4112.         {
  4113.           register tree normal_member;
  4114.  
  4115.           /* First output info about the data members and type members.  */
  4116.  
  4117.           for (normal_member = TYPE_FIELDS (type);
  4118.            normal_member;
  4119.            normal_member = TREE_CHAIN (normal_member))
  4120.             output_decl (normal_member, type);
  4121.         }
  4122.  
  4123.         {
  4124.           register tree vec_base;
  4125.  
  4126.           /* Now output info about the function members (if any).  */
  4127.  
  4128.           vec_base = TYPE_METHODS (type);
  4129.           if (vec_base)
  4130.         {
  4131.           register tree first_func_member = TREE_VEC_ELT (vec_base, 0);
  4132.           register tree func_member;
  4133.  
  4134.           /* This isn't documented, but the first element of the
  4135.              vector of member functions can be NULL in cases where
  4136.              the class type in question didn't have either a
  4137.              constructor or a destructor declared for it.  We have
  4138.              to make allowances for that here.  */
  4139.  
  4140.           if (first_func_member == NULL)
  4141.             first_func_member = TREE_VEC_ELT (vec_base, 1);
  4142.  
  4143.           for (func_member = first_func_member;
  4144.                func_member;
  4145.                func_member = TREE_CHAIN (func_member))
  4146.             output_decl (func_member, type);
  4147.         }
  4148.         }
  4149.  
  4150.         /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves
  4151.            scopes (at least in C++) so we must now output any nested
  4152.            pending types which are local just to this type.  */
  4153.  
  4154.         output_pending_types_for_scope (type);
  4155.  
  4156.         end_sibling_chain ();    /* Terminate member chain.  */
  4157.       }
  4158.  
  4159.     break;
  4160.  
  4161.       case VOID_TYPE:
  4162.       case INTEGER_TYPE:
  4163.       case REAL_TYPE:
  4164.       case COMPLEX_TYPE:
  4165.       case BOOLEAN_TYPE:
  4166.       case CHAR_TYPE:
  4167.     break;        /* No DIEs needed for fundamental types.  */
  4168.  
  4169.       case LANG_TYPE:    /* No Dwarf representation currently defined.  */
  4170.     break;
  4171.  
  4172.       default:
  4173.     abort ();
  4174.     }
  4175.  
  4176.   TREE_ASM_WRITTEN (type) = 1;
  4177. }
  4178.  
  4179. static void
  4180. output_tagged_type_instantiation (type)
  4181.      register tree type;
  4182. {
  4183.   if (type == 0 || type == error_mark_node)
  4184.     return;
  4185.  
  4186.   /* We are going to output a DIE to represent the unqualified version of
  4187.      of this type (i.e. without any const or volatile qualifiers) so make
  4188.      sure that we have the main variant (i.e. the unqualified version) of
  4189.      this type now.  */
  4190.  
  4191.   assert (type == type_main_variant (type));
  4192.  
  4193.   assert (TREE_ASM_WRITTEN (type));
  4194.  
  4195.   switch (TREE_CODE (type))
  4196.     {
  4197.       case ERROR_MARK:
  4198.     break;
  4199.  
  4200.       case ENUMERAL_TYPE:
  4201.     output_die (output_inlined_enumeration_type_die, type);
  4202.     break;
  4203.  
  4204.       case RECORD_TYPE:
  4205.     output_die (output_inlined_structure_type_die, type);
  4206.     break;
  4207.  
  4208.       case UNION_TYPE:
  4209.       case QUAL_UNION_TYPE:
  4210.     output_die (output_inlined_union_type_die, type);
  4211.     break;
  4212.  
  4213.       default:
  4214.     abort ();    /* Should never happen.  */
  4215.     }
  4216. }
  4217.  
  4218. /* Output a TAG_lexical_block DIE followed by DIEs to represent all of
  4219.    the things which are local to the given block.  */
  4220.  
  4221. static void
  4222. output_block (stmt)
  4223.     register tree stmt;
  4224. {
  4225.   register int must_output_die = 0;
  4226.   register tree origin;
  4227.   register enum tree_code origin_code;
  4228.  
  4229.   /* Ignore blocks never really used to make RTL.  */
  4230.  
  4231.   if (! stmt || ! TREE_USED (stmt))
  4232.     return;
  4233.  
  4234.   /* Determine the "ultimate origin" of this block.  This block may be an
  4235.      inlined instance of an inlined instance of inline function, so we
  4236.      have to trace all of the way back through the origin chain to find
  4237.      out what sort of node actually served as the original seed for the
  4238.      creation of the current block.  */
  4239.  
  4240.   origin = block_ultimate_origin (stmt);
  4241.   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
  4242.  
  4243.   /* Determine if we need to output any Dwarf DIEs at all to represent this
  4244.      block.  */
  4245.  
  4246.   if (origin_code == FUNCTION_DECL)
  4247.     /* The outer scopes for inlinings *must* always be represented.  We
  4248.        generate TAG_inlined_subroutine DIEs for them.  (See below.)  */
  4249.     must_output_die = 1;
  4250.   else
  4251.     {
  4252.       /* In the case where the current block represents an inlining of the
  4253.      "body block" of an inline function, we must *NOT* output any DIE
  4254.      for this block because we have already output a DIE to represent
  4255.      the whole inlined function scope and the "body block" of any
  4256.      function doesn't really represent a different scope according to
  4257.      ANSI C rules.  So we check here to make sure that this block does
  4258.      not represent a "body block inlining" before trying to set the
  4259.      `must_output_die' flag.  */
  4260.  
  4261.       if (origin == NULL || ! is_body_block (origin))
  4262.     {
  4263.       /* Determine if this block directly contains any "significant"
  4264.          local declarations which we will need to output DIEs for.  */
  4265.  
  4266.       if (debug_info_level > DINFO_LEVEL_TERSE)
  4267.         /* We are not in terse mode so *any* local declaration counts
  4268.            as being a "significant" one.  */
  4269.         must_output_die = (BLOCK_VARS (stmt) != NULL);
  4270.       else
  4271.         {
  4272.           register tree decl;
  4273.  
  4274.           /* We are in terse mode, so only local (nested) function
  4275.              definitions count as "significant" local declarations.  */
  4276.  
  4277.           for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
  4278.         if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
  4279.           {
  4280.             must_output_die = 1;
  4281.             break;
  4282.           }
  4283.         }
  4284.     }
  4285.     }
  4286.  
  4287.   /* It would be a waste of space to generate a Dwarf TAG_lexical_block
  4288.      DIE for any block which contains no significant local declarations
  4289.      at all.  Rather, in such cases we just call `output_decls_for_scope'
  4290.      so that any needed Dwarf info for any sub-blocks will get properly
  4291.      generated.  Note that in terse mode, our definition of what constitutes
  4292.      a "significant" local declaration gets restricted to include only
  4293.      inlined function instances and local (nested) function definitions.  */
  4294.  
  4295.   if (must_output_die)
  4296.     {
  4297.       output_die ((origin_code == FUNCTION_DECL)
  4298.             ? output_inlined_subroutine_die
  4299.             : output_lexical_block_die,
  4300.           stmt);
  4301.       output_decls_for_scope (stmt);
  4302.       end_sibling_chain ();
  4303.     }
  4304.   else
  4305.     output_decls_for_scope (stmt);
  4306. }
  4307.  
  4308. /* Output all of the decls declared within a given scope (also called
  4309.    a `binding contour') and (recursively) all of it's sub-blocks.  */
  4310.  
  4311. static void
  4312. output_decls_for_scope (stmt)
  4313.      register tree stmt;
  4314. {
  4315.   /* Ignore blocks never really used to make RTL.  */
  4316.  
  4317.   if (! stmt || ! TREE_USED (stmt))
  4318.     return;
  4319.  
  4320.   if (! BLOCK_ABSTRACT (stmt))
  4321.     next_block_number++;
  4322.  
  4323.   /* Output the DIEs to represent all of the data objects, functions,
  4324.      typedefs, and tagged types declared directly within this block
  4325.      but not within any nested sub-blocks.  */
  4326.  
  4327.   {
  4328.     register tree decl;
  4329.  
  4330.     for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl))
  4331.       output_decl (decl, stmt);
  4332.   }
  4333.  
  4334.   output_pending_types_for_scope (stmt);
  4335.  
  4336.   /* Output the DIEs to represent all sub-blocks (and the items declared
  4337.      therein) of this block.     */
  4338.  
  4339.   {
  4340.     register tree subblocks;
  4341.  
  4342.     for (subblocks = BLOCK_SUBBLOCKS (stmt);
  4343.          subblocks;
  4344.          subblocks = BLOCK_CHAIN (subblocks))
  4345.       output_block (subblocks);
  4346.   }
  4347. }
  4348.  
  4349. /* Output Dwarf .debug information for a decl described by DECL.  */
  4350.  
  4351. static void
  4352. output_decl (decl, containing_scope)
  4353.      register tree decl;
  4354.      register tree containing_scope;
  4355. {
  4356.   /* Make a note of the decl node we are going to be working on.  We may
  4357.      need to give the user the source coordinates of where it appeared in
  4358.      case we notice (later on) that something about it looks screwy.  */
  4359.  
  4360.   dwarf_last_decl = decl;
  4361.  
  4362.   if (TREE_CODE (decl) == ERROR_MARK)
  4363.     return;
  4364.  
  4365.   /* If this ..._DECL node is marked to be ignored, then ignore it.
  4366.      But don't ignore a function definition, since that would screw
  4367.      up our count of blocks, and that it turn will completely screw up the
  4368.      the labels we will reference in subsequent AT_low_pc and AT_high_pc
  4369.      attributes (for subsequent blocks).  */
  4370.  
  4371.   if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
  4372.     return;
  4373.  
  4374.   switch (TREE_CODE (decl))
  4375.     {
  4376.     case CONST_DECL:
  4377.       /* The individual enumerators of an enum type get output when we
  4378.      output the Dwarf representation of the relevant enum type itself.  */
  4379.       break;
  4380.  
  4381.     case FUNCTION_DECL:
  4382.       /* If we are in terse mode, don't output any DIEs to represent
  4383.      mere function declarations.  Also, if we are conforming
  4384.      to the DWARF version 1 specification, don't output DIEs for
  4385.      mere function declarations.  */
  4386.  
  4387.       if (DECL_INITIAL (decl) == NULL_TREE)
  4388. #if (DWARF_VERSION > 1)
  4389.     if (debug_info_level <= DINFO_LEVEL_TERSE)
  4390. #endif
  4391.       break;
  4392.  
  4393.       /* Before we describe the FUNCTION_DECL itself, make sure that we
  4394.      have described its return type.  */
  4395.  
  4396.       output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope);
  4397.  
  4398.       /* If the following DIE will represent a function definition for a
  4399.      function with "extern" linkage, output a special "pubnames" DIE
  4400.      label just ahead of the actual DIE.  A reference to this label
  4401.      was already generated in the .debug_pubnames section sub-entry
  4402.      for this function definition.  */
  4403.  
  4404.       if (TREE_PUBLIC (decl))
  4405.     {
  4406.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4407.  
  4408.       sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
  4409.       ASM_OUTPUT_LABEL (asm_out_file, label);
  4410.     }
  4411.  
  4412.       /* Now output a DIE to represent the function itself.  */
  4413.  
  4414.       output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
  4415.                 ? output_global_subroutine_die
  4416.                 : output_local_subroutine_die,
  4417.           decl);
  4418.  
  4419.       /* Now output descriptions of the arguments for this function.
  4420.      This gets (unnecessarily?) complex because of the fact that
  4421.      the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
  4422.      cases where there was a trailing `...' at the end of the formal
  4423.      parameter list.  In order to find out if there was a trailing
  4424.      ellipsis or not, we must instead look at the type associated
  4425.      with the FUNCTION_DECL.  This will be a node of type FUNCTION_TYPE.
  4426.      If the chain of type nodes hanging off of this FUNCTION_TYPE node
  4427.      ends with a void_type_node then there should *not* be an ellipsis
  4428.      at the end.  */
  4429.  
  4430.       /* In the case where we are describing a mere function declaration, all
  4431.      we need to do here (and all we *can* do here) is to describe
  4432.      the *types* of its formal parameters.  */
  4433.  
  4434.       if (DECL_INITIAL (decl) == NULL_TREE)
  4435.     output_formal_types (TREE_TYPE (decl));
  4436.       else
  4437.     {
  4438.       /* Generate DIEs to represent all known formal parameters */
  4439.  
  4440.       register tree arg_decls = DECL_ARGUMENTS (decl);
  4441.       register tree parm;
  4442.  
  4443.       /* WARNING!  Kludge zone ahead!  Here we have a special
  4444.          hack for svr4 SDB compatibility.  Instead of passing the
  4445.          current FUNCTION_DECL node as the second parameter (i.e.
  4446.          the `containing_scope' parameter) to `output_decl' (as
  4447.          we ought to) we instead pass a pointer to our own private
  4448.          fake_containing_scope node.  That node is a RECORD_TYPE
  4449.          node which NO OTHER TYPE may ever actually be a member of.
  4450.  
  4451.          This pointer will ultimately get passed into `output_type'
  4452.          as its `containing_scope' parameter.  `Output_type' will
  4453.          then perform its part in the hack... i.e. it will pend
  4454.          the type of the formal parameter onto the pending_types
  4455.          list.  Later on, when we are done generating the whole
  4456.          sequence of formal parameter DIEs for this function
  4457.          definition, we will un-pend all previously pended types
  4458.          of formal parameters for this function definition.
  4459.  
  4460.          This whole kludge prevents any type DIEs from being
  4461.          mixed in with the formal parameter DIEs.  That's good
  4462.          because svr4 SDB believes that the list of formal
  4463.          parameter DIEs for a function ends wherever the first
  4464.          non-formal-parameter DIE appears.  Thus, we have to
  4465.          keep the formal parameter DIEs segregated.  They must
  4466.          all appear (consecutively) at the start of the list of
  4467.          children for the DIE representing the function definition.
  4468.          Then (and only then) may we output any additional DIEs
  4469.          needed to represent the types of these formal parameters.
  4470.       */
  4471.  
  4472.       /*
  4473.          When generating DIEs, generate the unspecified_parameters
  4474.          DIE instead if we come across the arg "__builtin_va_alist"
  4475.       */
  4476.  
  4477.       for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
  4478.         if (TREE_CODE (parm) == PARM_DECL)
  4479.               {
  4480.         if (DECL_NAME(parm) &&
  4481.             !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)),
  4482.                 "__builtin_va_alist") )
  4483.           output_die (output_unspecified_parameters_die, decl);
  4484.             else
  4485.           output_decl (parm, fake_containing_scope);
  4486.           }
  4487.  
  4488.       /*
  4489.          Now that we have finished generating all of the DIEs to
  4490.          represent the formal parameters themselves, force out
  4491.          any DIEs needed to represent their types.  We do this
  4492.          simply by un-pending all previously pended types which
  4493.          can legitimately go into the chain of children DIEs for
  4494.          the current FUNCTION_DECL.
  4495.       */
  4496.  
  4497.       output_pending_types_for_scope (decl);
  4498.  
  4499.       /*
  4500.         Decide whether we need a unspecified_parameters DIE at the end.
  4501.         There are 2 more cases to do this for:
  4502.         1) the ansi ... declaration - this is detectable when the end
  4503.         of the arg list is not a void_type_node
  4504.         2) an unprototyped function declaration (not a definition).  This
  4505.         just means that we have no info about the parameters at all.
  4506.       */
  4507.  
  4508.       {
  4509.         register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
  4510.  
  4511.         if (fn_arg_types)
  4512.           {
  4513.           /* this is the prototyped case, check for ... */
  4514.           if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
  4515.             output_die (output_unspecified_parameters_die, decl);
  4516.               }
  4517.             else
  4518.               {
  4519.           /* this is unprotoyped, check for undefined (just declaration) */
  4520.               if (!DECL_INITIAL (decl))
  4521.                 output_die (output_unspecified_parameters_die, decl);
  4522.               }
  4523.       }
  4524.     }
  4525.  
  4526.       /* Output Dwarf info for all of the stuff within the body of the
  4527.      function (if it has one - it may be just a declaration).  */
  4528.  
  4529.       {
  4530.     register tree outer_scope = DECL_INITIAL (decl);
  4531.  
  4532.     if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
  4533.       {
  4534.         /* Note that here, `outer_scope' is a pointer to the outermost
  4535.            BLOCK node created to represent a function.
  4536.            This outermost BLOCK actually represents the outermost
  4537.            binding contour for the function, i.e. the contour in which
  4538.            the function's formal parameters and labels get declared.
  4539.  
  4540.            Curiously, it appears that the front end doesn't actually
  4541.            put the PARM_DECL nodes for the current function onto the
  4542.            BLOCK_VARS list for this outer scope.  (They are strung
  4543.            off of the DECL_ARGUMENTS list for the function instead.)
  4544.            The BLOCK_VARS list for the `outer_scope' does provide us
  4545.            with a list of the LABEL_DECL nodes for the function however,
  4546.            and we output DWARF info for those here.
  4547.  
  4548.            Just within the `outer_scope' there will be another BLOCK
  4549.            node representing the function's outermost pair of curly
  4550.            braces.  We musn't generate a lexical_block DIE for this
  4551.            outermost pair of curly braces because that is not really an
  4552.            independent scope according to ANSI C rules.  Rather, it is
  4553.            the same scope in which the parameters were declared.  */
  4554.  
  4555.         {
  4556.           register tree label;
  4557.  
  4558.           for (label = BLOCK_VARS (outer_scope);
  4559.            label;
  4560.            label = TREE_CHAIN (label))
  4561.         output_decl (label, outer_scope);
  4562.         }
  4563.  
  4564.         /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a
  4565.            list of BLOCK nodes which is always only one element long.
  4566.            That one element represents the outermost pair of curley
  4567.            braces for the function body.  */
  4568.  
  4569.         output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope));
  4570.  
  4571.         /* Finally, force out any pending types which are local to the
  4572.            outermost block of this function definition.  These will
  4573.            all have a TYPE_CONTEXT which points to the FUNCTION_DECL
  4574.            node itself.  */
  4575.  
  4576.         output_pending_types_for_scope (decl);
  4577.       }
  4578.       }
  4579.  
  4580.       /* Generate a terminator for the list of stuff `owned' by this
  4581.      function.  */
  4582.  
  4583.       end_sibling_chain ();
  4584.  
  4585.       break;
  4586.  
  4587.     case TYPE_DECL:
  4588.       /* If we are in terse mode, don't generate any DIEs to represent
  4589.      any actual typedefs.  Note that even when we are in terse mode,
  4590.      we must still output DIEs to represent those tagged types which
  4591.      are used (directly or indirectly) in the specification of either
  4592.      a return type or a formal parameter type of some function.  */
  4593.  
  4594.       if (debug_info_level <= DINFO_LEVEL_TERSE)
  4595.     if (DECL_NAME (decl) != NULL
  4596.         || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
  4597.           return;
  4598.  
  4599.       /* In the special case of a null-named TYPE_DECL node (representing
  4600.      the declaration of some type tag), if the given TYPE_DECL is
  4601.      marked as having been instantiated from some other (original)
  4602.      TYPE_DECL node (e.g. one which was generated within the original
  4603.      definition of an inline function) we have to generate a special
  4604.      (abbreviated) TAG_structure_type, TAG_union_type, or
  4605.      TAG_enumeration-type DIE here.  */
  4606.  
  4607.       if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl))
  4608.     {
  4609.       output_tagged_type_instantiation (TREE_TYPE (decl));
  4610.       return;
  4611.     }
  4612.  
  4613.       output_type (TREE_TYPE (decl), containing_scope);
  4614.  
  4615.       /* Note that unlike the gcc front end (which generates a NULL named
  4616.      TYPE_DECL node for each complete tagged type, each array type,
  4617.      and each function type node created) the g++ front end generates
  4618.      a *named* TYPE_DECL node for each tagged type node created.
  4619.      Unfortunately, these g++ TYPE_DECL nodes cause us to output many
  4620.      superfluous and unnecessary TAG_typedef DIEs here.  When g++ is
  4621.      fixed to stop generating these superfluous named TYPE_DECL nodes,
  4622.      the superfluous TAG_typedef DIEs will likewise cease.  */
  4623.  
  4624.       if (DECL_NAME (decl))
  4625.     /* Output a DIE to represent the typedef itself.  */
  4626.     output_die (output_typedef_die, decl);
  4627.       break;
  4628.  
  4629.     case LABEL_DECL:
  4630.       if (debug_info_level >= DINFO_LEVEL_NORMAL)
  4631.     output_die (output_label_die, decl);
  4632.       break;
  4633.  
  4634.     case VAR_DECL:
  4635.       /* If we are conforming to the DWARF version 1 specification, don't
  4636.      generated any DIEs to represent mere external object declarations.  */
  4637.  
  4638. #if (DWARF_VERSION <= 1)
  4639.       if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl))
  4640.     break;
  4641. #endif
  4642.  
  4643.       /* If we are in terse mode, don't generate any DIEs to represent
  4644.      any variable declarations or definitions.  */
  4645.  
  4646.       if (debug_info_level <= DINFO_LEVEL_TERSE)
  4647.         break;
  4648.  
  4649.       /* Output any DIEs that are needed to specify the type of this data
  4650.      object.  */
  4651.  
  4652.       output_type (TREE_TYPE (decl), containing_scope);
  4653.  
  4654.       /* If the following DIE will represent a data object definition for a
  4655.      data object with "extern" linkage, output a special "pubnames" DIE
  4656.      label just ahead of the actual DIE.  A reference to this label
  4657.      was already generated in the .debug_pubnames section sub-entry
  4658.      for this data object definition.  */
  4659.  
  4660.       if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl))
  4661.     {
  4662.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4663.  
  4664.       sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++);
  4665.       ASM_OUTPUT_LABEL (asm_out_file, label);
  4666.     }
  4667.  
  4668.       /* Now output the DIE to represent the data object itself.  This gets
  4669.      complicated because of the possibility that the VAR_DECL really
  4670.      represents an inlined instance of a formal parameter for an inline
  4671.      function.  */
  4672.  
  4673.       {
  4674.         register void (*func) ();
  4675.     register tree origin = decl_ultimate_origin (decl);
  4676.  
  4677.     if (origin != NULL && TREE_CODE (origin) == PARM_DECL)
  4678.       func = output_formal_parameter_die;
  4679.     else
  4680.       {
  4681.         if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
  4682.           func = output_global_variable_die;
  4683.         else
  4684.           func = output_local_variable_die;
  4685.       }
  4686.     output_die (func, decl);
  4687.       }
  4688.       break;
  4689.  
  4690.     case FIELD_DECL:
  4691.       /* Ignore the nameless fields that are used to skip bits.  */
  4692.       if (DECL_NAME (decl) != 0)
  4693.     {
  4694.       output_type (member_declared_type (decl), containing_scope);
  4695.           output_die (output_member_die, decl);
  4696.     }
  4697.       break;
  4698.  
  4699.     case PARM_DECL:
  4700.      /* Force out the type of this formal, if it was not forced out yet.
  4701.     Note that here we can run afowl of a bug in "classic" svr4 SDB.
  4702.     It should be able to grok the presence of type DIEs within a list
  4703.     of TAG_formal_parameter DIEs, but it doesn't.  */
  4704.  
  4705.       output_type (TREE_TYPE (decl), containing_scope);
  4706.       output_die (output_formal_parameter_die, decl);
  4707.       break;
  4708.  
  4709.     default:
  4710.       abort ();
  4711.     }
  4712. }
  4713.  
  4714. void
  4715. dwarfout_file_scope_decl (decl, set_finalizing)
  4716.      register tree decl;
  4717.      register int set_finalizing;
  4718. {
  4719.   if (TREE_CODE (decl) == ERROR_MARK)
  4720.     return;
  4721.  
  4722.   /* If this ..._DECL node is marked to be ignored, then ignore it.  We
  4723.      gotta hope that the node in question doesn't represent a function
  4724.      definition.  If it does, then totally ignoring it is bound to screw
  4725.      up our count of blocks, and that it turn will completely screw up the
  4726.      the labels we will reference in subsequent AT_low_pc and AT_high_pc
  4727.      attributes (for subsequent blocks).  (It's too bad that BLOCK nodes
  4728.      don't carry their own sequence numbers with them!)  */
  4729.  
  4730.   if (DECL_IGNORED_P (decl))
  4731.     {
  4732.       if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
  4733.     abort ();
  4734.       return;
  4735.     }
  4736.  
  4737.   switch (TREE_CODE (decl))
  4738.     {
  4739.     case FUNCTION_DECL:
  4740.  
  4741.       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of
  4742.      a builtin function.  Explicit programmer-supplied declarations of
  4743.      these same functions should NOT be ignored however.  */
  4744.  
  4745.       if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
  4746.         return;
  4747.  
  4748.       /* What we would really like to do here is to filter out all mere
  4749.      file-scope declarations of file-scope functions which are never
  4750.      referenced later within this translation unit (and keep all of
  4751.      ones that *are* referenced later on) but we aren't clarvoiant,
  4752.      so we have no idea which functions will be referenced in the
  4753.      future (i.e. later on within the current translation unit).
  4754.      So here we just ignore all file-scope function declarations
  4755.      which are not also definitions.  If and when the debugger needs
  4756.      to know something about these funcstion, it wil have to hunt
  4757.      around and find the DWARF information associated with the
  4758.      *definition* of the function.
  4759.  
  4760.      Note that we can't just check `DECL_EXTERNAL' to find out which
  4761.      FUNCTION_DECL nodes represent definitions and which ones represent
  4762.      mere declarations.  We have to check `DECL_INITIAL' instead.  That's
  4763.      because the C front-end supports some weird semantics for "extern
  4764.      inline" function definitions.  These can get inlined within the
  4765.      current translation unit (an thus, we need to generate DWARF info
  4766.      for their abstract instances so that the DWARF info for the
  4767.      concrete inlined instances can have something to refer to) but
  4768.      the compiler never generates any out-of-lines instances of such
  4769.      things (despite the fact that they *are* definitions).  The
  4770.      important point is that the C front-end marks these "extern inline"
  4771.      functions as DECL_EXTERNAL, but we need to generate DWARf for them
  4772.      anyway.
  4773.  
  4774.      Note that the C++ front-end also plays some similar games for inline
  4775.      function definitions appearing within include files which also
  4776.      contain `#pragma interface' pragmas.  */
  4777.  
  4778.       if (DECL_INITIAL (decl) == NULL_TREE)
  4779.     return;
  4780.  
  4781.       if (TREE_PUBLIC (decl)
  4782.       && ! DECL_EXTERNAL (decl)
  4783.       && ! DECL_ABSTRACT (decl))
  4784.     {
  4785.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4786.  
  4787.       /* Output a .debug_pubnames entry for a public function
  4788.          defined in this compilation unit.  */
  4789.  
  4790.       fputc ('\n', asm_out_file);
  4791.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
  4792.       sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
  4793.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  4794.       ASM_OUTPUT_DWARF_STRING (asm_out_file,
  4795.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  4796.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  4797.     }
  4798.  
  4799.       break;
  4800.  
  4801.     case VAR_DECL:
  4802.  
  4803.       /* Ignore this VAR_DECL if it refers to a file-scope extern data
  4804.      object declaration and if the declaration was never even
  4805.      referenced from within this entire compilation unit.  We
  4806.      suppress these DIEs in order to save space in the .debug section
  4807.      (by eliminating entries which are probably useless).  Note that
  4808.      we must not suppress block-local extern declarations (whether
  4809.      used or not) because that would screw-up the debugger's name
  4810.      lookup mechanism and cause it to miss things which really ought
  4811.      to be in scope at a given point.  */
  4812.  
  4813.       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
  4814.     return;
  4815.  
  4816.       if (TREE_PUBLIC (decl)
  4817.       && ! DECL_EXTERNAL (decl)
  4818.       && GET_CODE (DECL_RTL (decl)) == MEM
  4819.       && ! DECL_ABSTRACT (decl))
  4820.     {
  4821.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4822.  
  4823.       if (debug_info_level >= DINFO_LEVEL_NORMAL)
  4824.         {
  4825.           /* Output a .debug_pubnames entry for a public variable
  4826.              defined in this compilation unit.  */
  4827.  
  4828.           fputc ('\n', asm_out_file);
  4829.           ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
  4830.           sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number);
  4831.           ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  4832.           ASM_OUTPUT_DWARF_STRING (asm_out_file,
  4833.                        IDENTIFIER_POINTER (DECL_NAME (decl)));
  4834.           ASM_OUTPUT_POP_SECTION (asm_out_file);
  4835.         }
  4836.  
  4837.       if (DECL_INITIAL (decl) == NULL)
  4838.         {
  4839.           /* Output a .debug_aranges entry for a public variable
  4840.          which is tentatively defined in this compilation unit.  */
  4841.  
  4842.           fputc ('\n', asm_out_file);
  4843.           ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
  4844.           ASM_OUTPUT_DWARF_ADDR (asm_out_file,
  4845.                   IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
  4846.           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 
  4847.             (unsigned) int_size_in_bytes (TREE_TYPE (decl)));
  4848.           ASM_OUTPUT_POP_SECTION (asm_out_file);
  4849.         }
  4850.     }
  4851.  
  4852.       /* If we are in terse mode, don't generate any DIEs to represent
  4853.      any variable declarations or definitions.  */
  4854.  
  4855.       if (debug_info_level <= DINFO_LEVEL_TERSE)
  4856.         return;
  4857.  
  4858.       break;
  4859.  
  4860.     case TYPE_DECL:
  4861.       /* Don't bother trying to generate any DIEs to represent any of the
  4862.      normal built-in types for the language we are compiling, except
  4863.      in cases where the types in question are *not* DWARF fundamental
  4864.      types.  We make an exception in the case of non-fundamental types
  4865.      for the sake of objective C (and perhaps C++) because the GNU
  4866.      front-ends for these languages may in fact create certain "built-in"
  4867.      types which are (for example) RECORD_TYPEs.  In such cases, we
  4868.      really need to output these (non-fundamental) types because other
  4869.      DIEs may contain references to them.  */
  4870.  
  4871.       if (DECL_SOURCE_LINE (decl) == 0
  4872.       && type_is_fundamental (TREE_TYPE (decl)))
  4873.     return;
  4874.  
  4875.       /* If we are in terse mode, don't generate any DIEs to represent
  4876.      any actual typedefs.  Note that even when we are in terse mode,
  4877.      we must still output DIEs to represent those tagged types which
  4878.      are used (directly or indirectly) in the specification of either
  4879.      a return type or a formal parameter type of some function.  */
  4880.  
  4881.       if (debug_info_level <= DINFO_LEVEL_TERSE)
  4882.     if (DECL_NAME (decl) != NULL
  4883.         || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)))
  4884.           return;
  4885.  
  4886.       break;
  4887.  
  4888.     default:
  4889.       return;
  4890.     }
  4891.  
  4892.   fputc ('\n', asm_out_file);
  4893.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
  4894.   finalizing = set_finalizing;
  4895.   output_decl (decl, NULL_TREE);
  4896.  
  4897.   /* NOTE:  The call above to `output_decl' may have caused one or more
  4898.      file-scope named types (i.e. tagged types) to be placed onto the
  4899.      pending_types_list.  We have to get those types off of that list
  4900.      at some point, and this is the perfect time to do it.  If we didn't
  4901.      take them off now, they might still be on the list when cc1 finally
  4902.      exits.  That might be OK if it weren't for the fact that when we put
  4903.      types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag
  4904.      for these types, and that causes them never to be output unless
  4905.      `output_pending_types_for_scope' takes them off of the list and un-sets
  4906.      their TREE_ASM_WRITTEN flags.  */
  4907.  
  4908.   output_pending_types_for_scope (NULL_TREE);
  4909.  
  4910.   /* The above call should have totally emptied the pending_types_list.  */
  4911.  
  4912.   assert (pending_types == 0);
  4913.  
  4914.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  4915.  
  4916.   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL)
  4917.     current_funcdef_number++;
  4918. }
  4919.  
  4920. /* Output a marker (i.e. a label) for the beginning of the generated code
  4921.    for a lexical block.     */
  4922.  
  4923. void
  4924. dwarfout_begin_block (blocknum)
  4925.      register unsigned blocknum;
  4926. {
  4927.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4928.  
  4929.   text_section ();
  4930.   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
  4931.   ASM_OUTPUT_LABEL (asm_out_file, label);
  4932. }
  4933.  
  4934. /* Output a marker (i.e. a label) for the end of the generated code
  4935.    for a lexical block.     */
  4936.  
  4937. void
  4938. dwarfout_end_block (blocknum)
  4939.      register unsigned blocknum;
  4940. {
  4941.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4942.  
  4943.   text_section ();
  4944.   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
  4945.   ASM_OUTPUT_LABEL (asm_out_file, label);
  4946. }
  4947.  
  4948. /* Output a marker (i.e. a label) at a point in the assembly code which
  4949.    corresponds to a given source level label.  */
  4950.  
  4951. void
  4952. dwarfout_label (insn)
  4953.      register rtx insn;
  4954. {
  4955.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  4956.     {
  4957.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4958.  
  4959.       text_section ();
  4960.       sprintf (label, INSN_LABEL_FMT, current_funcdef_number,
  4961.                       (unsigned) INSN_UID (insn));
  4962.       ASM_OUTPUT_LABEL (asm_out_file, label);
  4963.     }
  4964. }
  4965.  
  4966. /* Output a marker (i.e. a label) for the point in the generated code where
  4967.    the real body of the function begins (after parameters have been moved
  4968.    to their home locations).  */
  4969.  
  4970. void
  4971. dwarfout_begin_function ()
  4972. {
  4973.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4974.  
  4975.   text_section ();
  4976.   sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number);
  4977.   ASM_OUTPUT_LABEL (asm_out_file, label);
  4978. }
  4979.  
  4980. /* Output a marker (i.e. a label) for the point in the generated code where
  4981.    the real body of the function ends (just before the epilogue code).  */
  4982.  
  4983. void
  4984. dwarfout_end_function ()
  4985. {
  4986.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  4987.  
  4988.   text_section ();
  4989.   sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number);
  4990.   ASM_OUTPUT_LABEL (asm_out_file, label);
  4991. }
  4992.  
  4993. /* Output a marker (i.e. a label) for the absolute end of the generated code
  4994.    for a function definition.  This gets called *after* the epilogue code
  4995.    has been generated.    */
  4996.  
  4997. void
  4998. dwarfout_end_epilogue ()
  4999. {
  5000.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5001.  
  5002.   /* Output a label to mark the endpoint of the code generated for this
  5003.      function.    */
  5004.  
  5005.   sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number);
  5006.   ASM_OUTPUT_LABEL (asm_out_file, label);
  5007. }
  5008.  
  5009. static void
  5010. shuffle_filename_entry (new_zeroth)
  5011.      register filename_entry *new_zeroth;
  5012. {
  5013.   filename_entry temp_entry;
  5014.   register filename_entry *limit_p;
  5015.   register filename_entry *move_p;
  5016.  
  5017.   if (new_zeroth == &filename_table[0])
  5018.     return;
  5019.  
  5020.   temp_entry = *new_zeroth;
  5021.  
  5022.   /* Shift entries up in the table to make room at [0].  */
  5023.  
  5024.   limit_p = &filename_table[0];
  5025.   for (move_p = new_zeroth; move_p > limit_p; move_p--)
  5026.     *move_p = *(move_p-1);
  5027.  
  5028.   /* Install the found entry at [0].  */
  5029.  
  5030.   filename_table[0] = temp_entry;
  5031. }
  5032.  
  5033. /* Create a new (string) entry for the .debug_sfnames section.  */
  5034.  
  5035. static void
  5036. generate_new_sfname_entry ()
  5037. {
  5038.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5039.  
  5040.   fputc ('\n', asm_out_file);
  5041.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
  5042.   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number);
  5043.   ASM_OUTPUT_LABEL (asm_out_file, label);
  5044.   ASM_OUTPUT_DWARF_STRING (asm_out_file,
  5045.                    filename_table[0].name
  5046.                  ? filename_table[0].name
  5047.                  : "");
  5048.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5049. }
  5050.  
  5051. /* Lookup a filename (in the list of filenames that we know about here in
  5052.    dwarfout.c) and return its "index".  The index of each (known) filename
  5053.    is just a unique number which is associated with only that one filename.
  5054.    We need such numbers for the sake of generating labels (in the
  5055.    .debug_sfnames section) and references to those unique labels (in the
  5056.    .debug_srcinfo and .debug_macinfo sections).
  5057.  
  5058.    If the filename given as an argument is not found in our current list,
  5059.    add it to the list and assign it the next available unique index number.
  5060.  
  5061.    Whatever we do (i.e. whether we find a pre-existing filename or add a new
  5062.    one), we shuffle the filename found (or added) up to the zeroth entry of
  5063.    our list of filenames (which is always searched linearly).  We do this so
  5064.    as to optimize the most common case for these filename lookups within
  5065.    dwarfout.c.  The most common case by far is the case where we call
  5066.    lookup_filename to lookup the very same filename that we did a lookup
  5067.    on the last time we called lookup_filename.  We make sure that this
  5068.    common case is fast because such cases will constitute 99.9% of the
  5069.    lookups we ever do (in practice).
  5070.  
  5071.    If we add a new filename entry to our table, we go ahead and generate
  5072.    the corresponding entry in the .debug_sfnames section right away.
  5073.    Doing so allows us to avoid tickling an assembler bug (present in some
  5074.    m68k assemblers) which yields assembly-time errors in cases where the
  5075.    difference of two label addresses is taken and where the two labels
  5076.    are in a section *other* than the one where the difference is being
  5077.    calculated, and where at least one of the two symbol references is a
  5078.    forward reference.  (This bug could be tickled by our .debug_srcinfo
  5079.    entries if we don't output their corresponding .debug_sfnames entries
  5080.    before them.)
  5081. */
  5082.  
  5083. static unsigned
  5084. lookup_filename (file_name)
  5085.      char *file_name;
  5086. {
  5087.   register filename_entry *search_p;
  5088.   register filename_entry *limit_p = &filename_table[ft_entries];
  5089.  
  5090.   for (search_p = filename_table; search_p < limit_p; search_p++)
  5091.     if (!strcmp (file_name, search_p->name))
  5092.       {
  5093.     /* When we get here, we have found the filename that we were
  5094.        looking for in the filename_table.  Now we want to make sure
  5095.        that it gets moved to the zero'th entry in the table (if it
  5096.        is not already there) so that subsequent attempts to find the
  5097.        same filename will find it as quickly as possible.  */
  5098.  
  5099.     shuffle_filename_entry (search_p);
  5100.         return filename_table[0].number;
  5101.       }
  5102.  
  5103.   /* We come here whenever we have a new filename which is not registered
  5104.      in the current table.  Here we add it to the table.  */
  5105.  
  5106.   /* Prepare to add a new table entry by making sure there is enough space
  5107.      in the table to do so.  If not, expand the current table.  */
  5108.  
  5109.   if (ft_entries == ft_entries_allocated)
  5110.     {
  5111.       ft_entries_allocated += FT_ENTRIES_INCREMENT;
  5112.       filename_table
  5113.     = (filename_entry *)
  5114.       xrealloc (filename_table,
  5115.             ft_entries_allocated * sizeof (filename_entry));
  5116.     }
  5117.  
  5118.   /* Initially, add the new entry at the end of the filename table.  */
  5119.  
  5120.   filename_table[ft_entries].number = ft_entries;
  5121.   filename_table[ft_entries].name = xstrdup (file_name);
  5122.  
  5123.   /* Shuffle the new entry into filename_table[0].  */
  5124.  
  5125.   shuffle_filename_entry (&filename_table[ft_entries]);
  5126.  
  5127.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  5128.     generate_new_sfname_entry ();
  5129.  
  5130.   ft_entries++;
  5131.   return filename_table[0].number;
  5132. }
  5133.  
  5134. static void
  5135. generate_srcinfo_entry (line_entry_num, files_entry_num)
  5136.      unsigned line_entry_num;
  5137.      unsigned files_entry_num;
  5138. {
  5139.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5140.  
  5141.   fputc ('\n', asm_out_file);
  5142.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
  5143.   sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
  5144.   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL);
  5145.   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num);
  5146.   ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL);
  5147.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5148. }
  5149.  
  5150. void
  5151. dwarfout_line (filename, line)
  5152.      register char *filename;
  5153.      register unsigned line;
  5154. {
  5155.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  5156.     {
  5157.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5158.       static unsigned last_line_entry_num = 0;
  5159.       static unsigned prev_file_entry_num = (unsigned) -1;
  5160.       register unsigned this_file_entry_num = lookup_filename (filename);
  5161.  
  5162.       text_section ();
  5163.       sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
  5164.       ASM_OUTPUT_LABEL (asm_out_file, label);
  5165.  
  5166.       fputc ('\n', asm_out_file);
  5167.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
  5168.  
  5169.       if (this_file_entry_num != prev_file_entry_num)
  5170.         {
  5171.           char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
  5172.  
  5173.           sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
  5174.           ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
  5175.         }
  5176.  
  5177.       {
  5178.         register char *tail = rindex (filename, '/');
  5179.  
  5180.         if (tail != NULL)
  5181.           filename = tail;
  5182.       }
  5183.  
  5184.       fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n",
  5185.            UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START,
  5186.            filename, line);
  5187.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
  5188.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL);
  5189.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5190.  
  5191.       if (this_file_entry_num != prev_file_entry_num)
  5192.         generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
  5193.       prev_file_entry_num = this_file_entry_num;
  5194.     }
  5195. }
  5196.  
  5197. /* Generate an entry in the .debug_macinfo section.  */
  5198.  
  5199. static void
  5200. generate_macinfo_entry (type_and_offset, string)
  5201.      register char *type_and_offset;
  5202.      register char *string;
  5203. {
  5204.   fputc ('\n', asm_out_file);
  5205.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
  5206.   fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset);
  5207.   ASM_OUTPUT_DWARF_STRING (asm_out_file, string);
  5208.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5209. }
  5210.  
  5211. void
  5212. dwarfout_start_new_source_file (filename)
  5213.      register char *filename;
  5214. {
  5215.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5216.   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3];
  5217.  
  5218.   sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename));
  5219.   sprintf (type_and_offset, "0x%08x+%s-%s",
  5220.        ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL);
  5221.   generate_macinfo_entry (type_and_offset, "");
  5222. }
  5223.  
  5224. void
  5225. dwarfout_resume_previous_source_file (lineno)
  5226.      register unsigned lineno;
  5227. {
  5228.   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
  5229.  
  5230.   sprintf (type_and_offset, "0x%08x+%u",
  5231.        ((unsigned) MACINFO_resume << 24), lineno);
  5232.   generate_macinfo_entry (type_and_offset, "");
  5233. }
  5234.  
  5235. /* Called from check_newline in c-parse.y.  The `buffer' parameter
  5236.    contains the tail part of the directive line, i.e. the part which
  5237.    is past the initial whitespace, #, whitespace, directive-name,
  5238.    whitespace part.  */
  5239.  
  5240. void
  5241. dwarfout_define (lineno, buffer)
  5242.      register unsigned lineno;
  5243.      register char *buffer;
  5244. {
  5245.   static int initialized = 0;
  5246.   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
  5247.  
  5248.   if (!initialized)
  5249.     {
  5250.       dwarfout_start_new_source_file (primary_filename);
  5251.       initialized = 1;
  5252.     }
  5253.   sprintf (type_and_offset, "0x%08x+%u",
  5254.        ((unsigned) MACINFO_define << 24), lineno);
  5255.   generate_macinfo_entry (type_and_offset, buffer);
  5256. }
  5257.  
  5258. /* Called from check_newline in c-parse.y.  The `buffer' parameter
  5259.    contains the tail part of the directive line, i.e. the part which
  5260.    is past the initial whitespace, #, whitespace, directive-name,
  5261.    whitespace part.  */
  5262.  
  5263. void
  5264. dwarfout_undef (lineno, buffer)
  5265.      register unsigned lineno;
  5266.      register char *buffer;
  5267. {
  5268.   char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2];
  5269.  
  5270.   sprintf (type_and_offset, "0x%08x+%u",
  5271.        ((unsigned) MACINFO_undef << 24), lineno);
  5272.   generate_macinfo_entry (type_and_offset, buffer);
  5273. }
  5274.  
  5275. /* Set up for Dwarf output at the start of compilation.     */
  5276.  
  5277. void
  5278. dwarfout_init (asm_out_file, main_input_filename)
  5279.      register FILE *asm_out_file;
  5280.      register char *main_input_filename;
  5281. {
  5282.   /* Remember the name of the primary input file.  */
  5283.  
  5284.   primary_filename = main_input_filename;
  5285.  
  5286.   /* Allocate the initial hunk of the pending_sibling_stack.  */
  5287.  
  5288.   pending_sibling_stack
  5289.     = (unsigned *)
  5290.     xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned));
  5291.   pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT;
  5292.   pending_siblings = 1;
  5293.  
  5294.   /* Allocate the initial hunk of the filename_table.  */
  5295.  
  5296.   filename_table
  5297.     = (filename_entry *)
  5298.     xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry));
  5299.   ft_entries_allocated = FT_ENTRIES_INCREMENT;
  5300.   ft_entries = 0;
  5301.  
  5302.   /* Allocate the initial hunk of the pending_types_list.  */
  5303.  
  5304.   pending_types_list
  5305.     = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree));
  5306.   pending_types_allocated = PENDING_TYPES_INCREMENT;
  5307.   pending_types = 0;
  5308.  
  5309.   /* Create an artificial RECORD_TYPE node which we can use in our hack
  5310.      to get the DIEs representing types of formal parameters to come out
  5311.      only *after* the DIEs for the formal parameters themselves.  */
  5312.  
  5313.   fake_containing_scope = make_node (RECORD_TYPE);
  5314.  
  5315.   /* Output a starting label for the .text section.  */
  5316.  
  5317.   fputc ('\n', asm_out_file);
  5318.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
  5319.   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
  5320.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5321.  
  5322.   /* Output a starting label for the .data section.  */
  5323.  
  5324.   fputc ('\n', asm_out_file);
  5325.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
  5326.   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
  5327.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5328.  
  5329. #if 0 /* GNU C doesn't currently use .data1.  */
  5330.   /* Output a starting label for the .data1 section.  */
  5331.  
  5332.   fputc ('\n', asm_out_file);
  5333.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
  5334.   ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL);
  5335.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5336. #endif
  5337.  
  5338.   /* Output a starting label for the .rodata section.  */
  5339.  
  5340.   fputc ('\n', asm_out_file);
  5341.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
  5342.   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
  5343.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5344.  
  5345. #if 0 /* GNU C doesn't currently use .rodata1.  */
  5346.   /* Output a starting label for the .rodata1 section.  */
  5347.  
  5348.   fputc ('\n', asm_out_file);
  5349.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
  5350.   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL);
  5351.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5352. #endif
  5353.  
  5354.   /* Output a starting label for the .bss section.  */
  5355.  
  5356.   fputc ('\n', asm_out_file);
  5357.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
  5358.   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
  5359.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5360.  
  5361.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  5362.     {
  5363.       /* Output a starting label and an initial (compilation directory)
  5364.      entry for the .debug_sfnames section.  The starting label will be
  5365.      referenced by the initial entry in the .debug_srcinfo section.  */
  5366.     
  5367.       fputc ('\n', asm_out_file);
  5368.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION);
  5369.       ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL);
  5370.       {
  5371.     register char *pwd;
  5372.     register unsigned len;
  5373.     register char *dirname;
  5374.  
  5375.     pwd = getpwd ();
  5376.     if (!pwd)
  5377.       pfatal_with_name ("getpwd");
  5378.     len = strlen (pwd);
  5379.     dirname = (char *) xmalloc (len + 2);
  5380.     
  5381.     strcpy (dirname, pwd);
  5382.     strcpy (dirname + len, "/");
  5383.         ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
  5384.         free (dirname);
  5385.       }
  5386.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5387.     
  5388.       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  5389.     {
  5390.           /* Output a starting label for the .debug_macinfo section.  This
  5391.          label will be referenced by the AT_mac_info attribute in the
  5392.          TAG_compile_unit DIE.  */
  5393.         
  5394.           fputc ('\n', asm_out_file);
  5395.           ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
  5396.           ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL);
  5397.           ASM_OUTPUT_POP_SECTION (asm_out_file);
  5398.     }
  5399.  
  5400.       /* Generate the initial entry for the .line section.  */
  5401.     
  5402.       fputc ('\n', asm_out_file);
  5403.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
  5404.       ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
  5405.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
  5406.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
  5407.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5408.     
  5409.       /* Generate the initial entry for the .debug_srcinfo section.  */
  5410.     
  5411.       fputc ('\n', asm_out_file);
  5412.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
  5413.       ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
  5414.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL);
  5415.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL);
  5416.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
  5417.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
  5418. #ifdef DWARF_TIMESTAMPS
  5419.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL));
  5420. #else
  5421.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
  5422. #endif
  5423.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5424.     
  5425.       /* Generate the initial entry for the .debug_pubnames section.  */
  5426.     
  5427.       fputc ('\n', asm_out_file);
  5428.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
  5429.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
  5430.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5431.     
  5432.       /* Generate the initial entry for the .debug_aranges section.  */
  5433.     
  5434.       fputc ('\n', asm_out_file);
  5435.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
  5436.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL);
  5437.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5438.     }
  5439.  
  5440.   /* Setup first DIE number == 1.  */
  5441.   NEXT_DIE_NUM = next_unused_dienum++;
  5442.  
  5443.   /* Generate the initial DIE for the .debug section.  Note that the
  5444.      (string) value given in the AT_name attribute of the TAG_compile_unit
  5445.      DIE will (typically) be a relative pathname and that this pathname
  5446.      should be taken as being relative to the directory from which the
  5447.      compiler was invoked when the given (base) source file was compiled.  */
  5448.  
  5449.   fputc ('\n', asm_out_file);
  5450.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
  5451.   ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL);
  5452.   output_die (output_compile_unit_die, main_input_filename);
  5453.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5454.  
  5455.   fputc ('\n', asm_out_file);
  5456. }
  5457.  
  5458. /* Output stuff that dwarf requires at the end of every file.  */
  5459.  
  5460. void
  5461. dwarfout_finish ()
  5462. {
  5463.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  5464.  
  5465.   fputc ('\n', asm_out_file);
  5466.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION);
  5467.  
  5468.   /* Mark the end of the chain of siblings which represent all file-scope
  5469.      declarations in this compilation unit.  */
  5470.  
  5471.   /* The (null) DIE which represents the terminator for the (sibling linked)
  5472.      list of file-scope items is *special*.  Normally, we would just call
  5473.      end_sibling_chain at this point in order to output a word with the
  5474.      value `4' and that word would act as the terminator for the list of
  5475.      DIEs describing file-scope items.  Unfortunately, if we were to simply
  5476.      do that, the label that would follow this DIE in the .debug section
  5477.      (i.e. `..D2') would *not* be properly aligned (as it must be on some
  5478.      machines) to a 4 byte boundary.
  5479.  
  5480.      In order to force the label `..D2' to get aligned to a 4 byte boundary,
  5481.      the trick used is to insert extra (otherwise useless) padding bytes
  5482.      into the (null) DIE that we know must precede the ..D2 label in the
  5483.      .debug section.  The amount of padding required can be anywhere between
  5484.      0 and 3 bytes.  The length word at the start of this DIE (i.e. the one
  5485.      with the padding) would normally contain the value 4, but now it will
  5486.      also have to include the padding bytes, so it will instead have some
  5487.      value in the range 4..7.
  5488.  
  5489.      Fortunately, the rules of Dwarf say that any DIE whose length word
  5490.      contains *any* value less than 8 should be treated as a null DIE, so
  5491.      this trick works out nicely.  Clever, eh?  Don't give me any credit
  5492.      (or blame).  I didn't think of this scheme.  I just conformed to it.
  5493.   */
  5494.  
  5495.   output_die (output_padded_null_die, (void *)0);
  5496.   dienum_pop ();
  5497.  
  5498.   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
  5499.   ASM_OUTPUT_LABEL (asm_out_file, label);    /* should be ..D2 */
  5500.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5501.  
  5502.   /* Output a terminator label for the .text section.  */
  5503.  
  5504.   fputc ('\n', asm_out_file);
  5505.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION);
  5506.   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
  5507.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5508.  
  5509.   /* Output a terminator label for the .data section.  */
  5510.  
  5511.   fputc ('\n', asm_out_file);
  5512.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION);
  5513.   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
  5514.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5515.  
  5516. #if 0 /* GNU C doesn't currently use .data1.  */
  5517.   /* Output a terminator label for the .data1 section.  */
  5518.  
  5519.   fputc ('\n', asm_out_file);
  5520.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION);
  5521.   ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL);
  5522.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5523. #endif
  5524.  
  5525.   /* Output a terminator label for the .rodata section.  */
  5526.  
  5527.   fputc ('\n', asm_out_file);
  5528.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION);
  5529.   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
  5530.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5531.  
  5532. #if 0 /* GNU C doesn't currently use .rodata1.  */
  5533.   /* Output a terminator label for the .rodata1 section.  */
  5534.  
  5535.   fputc ('\n', asm_out_file);
  5536.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION);
  5537.   ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL);
  5538.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5539. #endif
  5540.  
  5541.   /* Output a terminator label for the .bss section.  */
  5542.  
  5543.   fputc ('\n', asm_out_file);
  5544.   ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION);
  5545.   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
  5546.   ASM_OUTPUT_POP_SECTION (asm_out_file);
  5547.  
  5548.   if (debug_info_level >= DINFO_LEVEL_NORMAL)
  5549.     {
  5550.       /* Output a terminating entry for the .line section.  */
  5551.     
  5552.       fputc ('\n', asm_out_file);
  5553.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION);
  5554.       ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL);
  5555.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  5556.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
  5557.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
  5558.       ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
  5559.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5560.     
  5561.       /* Output a terminating entry for the .debug_srcinfo section.  */
  5562.     
  5563.       fputc ('\n', asm_out_file);
  5564.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION);
  5565.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
  5566.                    LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL);
  5567.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
  5568.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5569.  
  5570.       if (debug_info_level >= DINFO_LEVEL_VERBOSE)
  5571.     {
  5572.       /* Output terminating entries for the .debug_macinfo section.  */
  5573.     
  5574.       dwarfout_resume_previous_source_file (0);
  5575.  
  5576.       fputc ('\n', asm_out_file);
  5577.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION);
  5578.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  5579.       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
  5580.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5581.     }
  5582.     
  5583.       /* Generate the terminating entry for the .debug_pubnames section.  */
  5584.     
  5585.       fputc ('\n', asm_out_file);
  5586.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION);
  5587.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  5588.       ASM_OUTPUT_DWARF_STRING (asm_out_file, "");
  5589.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5590.     
  5591.       /* Generate the terminating entries for the .debug_aranges section.
  5592.  
  5593.      Note that we want to do this only *after* we have output the end
  5594.      labels (for the various program sections) which we are going to
  5595.      refer to here.  This allows us to work around a bug in the m68k
  5596.      svr4 assembler.  That assembler gives bogus assembly-time errors
  5597.      if (within any given section) you try to take the difference of
  5598.      two relocatable symbols, both of which are located within some
  5599.      other section, and if one (or both?) of the symbols involved is
  5600.      being forward-referenced.  By generating the .debug_aranges
  5601.      entries at this late point in the assembly output, we skirt the
  5602.      issue simply by avoiding forward-references.
  5603.       */
  5604.     
  5605.       fputc ('\n', asm_out_file);
  5606.       ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION);
  5607.  
  5608.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
  5609.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
  5610.  
  5611.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
  5612.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL);
  5613.  
  5614. #if 0 /* GNU C doesn't currently use .data1.  */
  5615.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL);
  5616.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL,
  5617.                          DATA1_BEGIN_LABEL);
  5618. #endif
  5619.  
  5620.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
  5621.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL,
  5622.                          RODATA_BEGIN_LABEL);
  5623.  
  5624. #if 0 /* GNU C doesn't currently use .rodata1.  */
  5625.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL);
  5626.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL,
  5627.                          RODATA1_BEGIN_LABEL);
  5628. #endif
  5629.  
  5630.       ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
  5631.       ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL);
  5632.  
  5633.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  5634.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  5635.  
  5636.       ASM_OUTPUT_POP_SECTION (asm_out_file);
  5637.     }
  5638. }
  5639.  
  5640. #endif /* DWARF_DEBUGGING_INFO */
  5641.